Search in sources :

Example 51 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class EsxHostDiscoveryAdapter method findExistingHost.

/**
 * Find an existing host with matching label or ip address
 *
 * @param hostSystem
 *            the host system to use
 * @return host that has a matching label or ip address, null if can't be
 *         found
 */
protected Host findExistingHost(HostSystem hostSystem) {
    List<Host> hosts = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, Host.class, PrefixConstraint.Factory.getFullMatchConstraint(Host.class, "label", hostSystem.getName()));
    for (Host host : hosts) {
        if (isEsxOtherOrNoOsHost(host)) {
            return host;
        }
    }
    List<Host> results = CustomQueryUtility.queryActiveResourcesByAltId(dbClient, Host.class, "hostName", hostSystem.getName());
    for (Host host : results) {
        if (isEsxOtherOrNoOsHost(host)) {
            return host;
        }
    }
    List<String> ipAddresses = getHostIpAddresses(hostSystem);
    for (String ipAddress : ipAddresses) {
        hosts = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, Host.class, PrefixConstraint.Factory.getFullMatchConstraint(Host.class, "label", ipAddress));
        for (Host host : hosts) {
            if (isEsxOtherOrNoOsHost(host)) {
                return host;
            }
        }
    }
    return null;
}
Also used : Host(com.emc.storageos.db.client.model.Host)

Example 52 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method addStepsPreOsInstall.

/**
 * Create/Add Pre-OS install steps to the workflow.
 *
 * @param workflow
 *            {@link Workflow} instance
 * @param waitFor
 *            If non-null, the step will not be queued for execution in the
 *            Dispatcher until the Step or StepGroup indicated by the
 *            waitFor has completed. The waitFor may either be a string
 *            representation of a Step UUID, or the name of a StepGroup.
 * @param computeSystemId
 *            {@link URI} computeSystem Id
 * @param hostId
 *            {@link URI} host Id
 * @param prepStepId
 *            {@link String} step Id
 * @return waitFor step name
 */
@Override
public String addStepsPreOsInstall(Workflow workflow, String waitFor, URI computeSystemId, URI hostId, String prepStepId) {
    log.info("addStepsPreOsInstall");
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
    Host host = _dbClient.queryObject(Host.class, hostId);
    ComputeElement ce = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
    // TODO COP-28960 check for null ce
    URI computeElementId = ce.getId();
    log.info("sptId:" + ce.getSptId());
    if (ce.getSptId() != null) {
        URI sptId = URI.create(ce.getSptId());
        UCSServiceProfileTemplate template = _dbClient.queryObject(UCSServiceProfileTemplate.class, sptId);
        // TODO COP-28960 check template not null
        log.info("is updating:" + template.getUpdating());
        if (template.getUpdating()) {
            waitFor = workflow.createStep(UNBIND_HOST_FROM_TEMPLATE, "prepare host for os install by unbinding it from service profile template", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("unbindHostFromTemplateStep", computeSystemId, hostId), new Workflow.Method("rollbackUnbindHostFromTemplate", computeSystemId, hostId), null);
        }
        // Set host to boot from lan
        waitFor = workflow.createStep(OS_INSTALL_SET_LAN_BOOT, "Set the host to boot from LAN", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("setLanBootTargetStep", computeSystemId, computeElementId, hostId), new Workflow.Method("setNoBootStep", computeSystemId, computeElementId, hostId), null);
        // Set the OS install Vlan on the first vnic
        waitFor = workflow.createStep(OS_INSTALL_PREPARE_OS_NETWORK, "prepare network for os install", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("prepareOsInstallNetworkStep", computeSystemId, computeElementId), new Workflow.Method("rollbackOsInstallNetwork", computeSystemId, computeElementId, prepStepId), prepStepId);
    } else {
        log.error("sptId is null!");
        throw new IllegalArgumentException("addStepsPreOsInstall method failed.  Could not find Serviceprofile template id from computeElement" + ce.getLabel());
    }
    return waitFor;
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Example 53 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method deleteBlockBootVolume.

/**
 * Deactivates or deletes the boot volume
 *
 * @param hostId
 *            {@link URI} hostId URI
 * @param volumeDescriptors
 *            {@link List<VolumeDescriptor>} list of boot volumes to delete
 * @param stepId
 *            {@link String} step id
 */
public void deleteBlockBootVolume(URI hostId, List<VolumeDescriptor> volumeDescriptors, String stepId) {
    log.info("deleteBlockBootVolume");
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (host == null) {
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        String task = stepId;
        URI bootVolumeId = getBootVolumeIdFromDescriptors(volumeDescriptors, host);
        Volume bootVolume = _dbClient.queryObject(Volume.class, bootVolumeId);
        if (bootVolume == null) {
            // No boot volume found, so it was already deleted.
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        Operation op = _dbClient.createTaskOpStatus(Volume.class, bootVolume.getId(), task, ResourceOperationTypeEnum.DELETE_BLOCK_VOLUME);
        bootVolume.getOpStatus().put(task, op);
        _dbClient.updateObject(bootVolume);
        final String workflowKey = "deleteVolumes";
        if (!WorkflowService.getInstance().hasWorkflowBeenCreated(task, workflowKey)) {
            blockOrchestrationController.deleteVolumes(volumeDescriptors, task);
            // Mark this workflow as created/executed so we don't do it
            // again on retry/resume
            WorkflowService.getInstance().markWorkflowBeenCreated(task, workflowKey);
        }
    } catch (Exception exception) {
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToDeactivateHost(host != null ? host.getHostName() : hostId.toString(), exception);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 54 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method deactivateComputeSystemHost.

/**
 * Deactivate compute system host
 *
 * @param csId
 *            {@link URI} compute system URI
 * @param hostId
 *            {@link URI} host URI
 * @param stepId
 *            step id
 */
public void deactivateComputeSystemHost(URI csId, URI hostId, String stepId) {
    log.info("deactivateComputeSystemHost");
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, csId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (null != host) {
            // Added check before we get here
            if (NullColumnValueGetter.isNullURI(host.getComputeElement()) && NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
                // NO-OP
                log.info("Host " + host.getLabel() + " has no computeElement association and no service profile association");
                WorkflowStepCompleter.stepSucceded(stepId);
                return;
            }
            getDevice(cs.getSystemType()).deactivateHost(cs, host);
        } else {
            throw new RuntimeException("Host null for uri " + hostId);
        }
    } catch (Exception exception) {
        log.error("Error on deactivate ComputeSystemHost with hostid {} and computementid {}", hostId, csId, exception);
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToDeactivateHost(host != null ? host.getHostName() : hostId.toString(), exception);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
        return;
    }
    WorkflowStepCompleter.stepSucceded(stepId);
}
Also used : ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Host(com.emc.storageos.db.client.model.Host) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 55 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method addStepsVcenterHostCleanup.

/**
 * Method to add steps to perform host cleanup operations on the vcenter
 *
 * @param workflow
 *            {@link Workflow} instance
 * @param waitFor
 *            {@link String} If non-null, the step will not be queued for
 *            execution in the Dispatcher until the Step or StepGroup
 *            indicated by the waitFor has completed. The waitFor may either
 *            be a string representation of a Step UUID, or the name of a
 *            StepGroup.
 * @param hostId
 *            {@link URI} hostId URI
 * @return waitFor step name
 */
@Override
public String addStepsVcenterHostCleanup(Workflow workflow, String waitFor, URI hostId) throws InternalException {
    Host host = _dbClient.queryObject(Host.class, hostId);
    if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        /**
         * No steps need to be added - as this was not a host that we
         * created in ViPR. If it was computeElement property of the host
         * would have been set.
         */
        log.info("Skipping VCenter Host cleanup for host with no blade association.  Host is " + hostId);
        return waitFor;
    }
    ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
    if (computeElement != null) {
        ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeElement.getComputeSystem());
        waitFor = workflow.createStep(CHECK_HOST_INITIATORS, "Check for host initiators", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("checkHostInitiators", hostId), null, null);
        // any update to the host using the hostService automatically adds this association.
        if (!NullColumnValueGetter.isNullURI(host.getVcenterDataCenter()) && host.getType() != null && host.getType().equalsIgnoreCase((Host.HostType.No_OS).name())) {
            log.info("Skipping Vcenter host cleanup steps because No_OS is specified on host " + hostId);
        } else {
            waitFor = workflow.createStep(DEACTIVATION_MAINTENANCE_MODE, "If synced with vCenter, put the host in maintenance mode", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("putHostInMaintenanceMode", hostId), null, null);
            waitFor = workflow.createStep(DEACTIVATION_REMOVE_HOST_VCENTER, "If synced with vCenter, remove the host from the cluster", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("removeHostFromVcenterCluster", hostId), null, null);
        }
    }
    return waitFor;
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16