Search in sources :

Example 6 with UCSServiceProfile

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

the class UcsComputeDevice method persistServiceProfileForHost.

private UCSServiceProfile persistServiceProfileForHost(LsServer lsServer, ComputeSystem cs, URI hostId) {
    Host host = _dbClient.queryObject(Host.class, hostId);
    if (host == null) {
        LOGGER.error("Host not found for URI:" + hostId.toString());
        throw ComputeSystemControllerException.exceptions.hostNotFound(hostId.toString());
    }
    UCSServiceProfile serviceProfile = new UCSServiceProfile();
    URI uri = URIUtil.createId(UCSServiceProfile.class);
    serviceProfile.setComputeSystem(cs.getId());
    serviceProfile.setInactive(false);
    serviceProfile.setId(uri);
    serviceProfile.setSystemType(cs.getSystemType());
    serviceProfile.setCreationTime(Calendar.getInstance());
    serviceProfile.setDn(lsServer.getDn());
    serviceProfile.setLabel(lsServer.getName());
    serviceProfile.setUuid(lsServer.getUuid());
    serviceProfile.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(cs, serviceProfile));
    serviceProfile.setHost(hostId);
    _dbClient.createObject(serviceProfile);
    host.setServiceProfile(serviceProfile.getId());
    _dbClient.updateObject(host);
    return serviceProfile;
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 7 with UCSServiceProfile

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

the class UcsComputeDevice method unbindHostFromComputeElement.

/*
     * Unbinds the host's service profile from the associated blade.
     * Determines the service profile to unbind using host's serviceProfile association.
     * In case of host provisioned using pre-Anakin version of ViPR and no serviceProfile association yet set,
     * serviceprofile to unbind will be determined by trying to find a serviceProfile that matches
     * the computeElement's uuid.
     */
private void unbindHostFromComputeElement(ComputeSystem cs, Host host) throws ClientGeneralException {
    // We already checked for empty initiators in a step before we get here
    if (host != null && !NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
        if (computeElement == null) {
            LOGGER.error("Host " + host.getLabel() + " has associated computeElementURI: " + host.getComputeElement() + " which is an invalid reference");
            LOGGER.info("Service profile unbind will not be triggered");
            return;
        }
        String spDn = null;
        LOGGER.info("Host.uuid: " + host.getUuid() + " ComputeElement.uuid: " + computeElement.getUuid());
        if (NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
            LOGGER.error("Host has no asscoaited serviceProfile. Service profile unbind will not be triggered.");
            return;
        }
        UCSServiceProfile serviceProfile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
        if (serviceProfile == null) {
            LOGGER.error("Host " + host.getLabel() + " has associated serviceProfileURI: " + host.getServiceProfile() + " which is an invalid reference");
            LOGGER.info("Service profile unbind will not be triggered");
            return;
        } else {
            spDn = serviceProfile.getDn();
            LOGGER.info("Host.uuid: " + host.getUuid() + " ComputeElement.uuid: " + computeElement.getUuid() + "serviceProfile.uuid:" + serviceProfile.getUuid());
        }
        if (spDn != null) {
            LOGGER.info("Unbinding service profile with dn: " + spDn);
            StringBuilder errorMessage = new StringBuilder();
            LsServer unboundServiceProfile = ucsmService.unbindServiceProfile(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), spDn, errorMessage);
            LOGGER.info("Operational state of Deleted Service Profile : " + unboundServiceProfile.getOperState());
            ComputeBlade computeBlade = pullAndPollManagedObject(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getLabel(), ComputeBlade.class);
            if (computeBlade == null) {
                LOGGER.info("ComputeBlade " + computeElement.getLabel() + " not found on UCS");
            } else {
                // Release the computeElement back into the pool as soon as we have unbound it from the service profile
                if (LsServerOperStates.UNASSOCIATED.equals(LsServerOperStates.fromString(computeBlade.getOperState()))) {
                    computeElement.setAvailable(true);
                }
                String originalUuid = computeElement.getOriginalUuid();
                LOGGER.info("ComputeBlade " + computeElement.getLabel() + " setting uuid back to originalUUid: " + originalUuid);
                computeElement.setUuid(originalUuid);
                _dbClient.updateObject(computeElement);
            }
        } else {
            LOGGER.error("spDn is null. Cannot determine the service profile to unbind");
        }
    } else {
        LOGGER.info("NO OP. Host is null or has no associated compute element");
    }
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) ComputeBlade(com.emc.cloud.platform.ucs.out.model.ComputeBlade) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer)

Example 8 with UCSServiceProfile

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

the class UcsComputeDevice method createLsServer.

/**
 * Create a LsServer
 * @param cs ComputeSystem instance
 * @param sptDn serviceProfile template distinguished name (DN)
 * @param host Host being created
 * @param stepId Id of step being executed.
 * @return LsServer instance
 */
public boolean createLsServer(ComputeSystem cs, String sptDn, Host host, String stepId) {
    WorkflowStepCompleter.stepExecuting(stepId);
    LOGGER.info("Creating Service Profile : " + host.getHostName() + " from Service Profile Template : " + sptDn);
    LsServer lsServer = null;
    StringBuffer errorMessage = new StringBuffer();
    try {
        lsServer = ucsmService.createServiceProfileFromTemplate(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), sptDn, host.getHostName(), errorMessage);
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_073);
        if (lsServer == null) {
            if (errorMessage != null && errorMessage.length() != 0) {
                throw new RuntimeException("UCS call to create service profile from template " + sptDn + " specified in compute virtual pool failed" + "\n \t " + errorMessage.toString());
            } else {
                throw new RuntimeException("UCS call to create service profile from template " + sptDn + " specified in compute virtual pool failed");
            }
        }
        workflowService.storeStepData(stepId, lsServer.getDn());
        UCSServiceProfile serviceProfile = persistServiceProfileForHost(lsServer, cs, host.getId());
        validateNewServiceProfile(cs, serviceProfile, host);
        String lsServerDn = lsServer.getDn();
        lsServer = pullAndPollManagedObject(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), lsServer.getDn(), LsServer.class);
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_061);
        if (lsServer == null) {
            throw new RuntimeException("UCS call to poll for ManagedObject " + lsServerDn + " failed, null LsServer was returned.");
        }
    } catch (Exception e) {
        LOGGER.error("Unable to createLsServer from template " + sptDn + " specified in compute virtual pool", e);
        WorkflowStepCompleter.stepFailed(stepId, ComputeSystemControllerException.exceptions.unableToProvisionHost(host.getHostName(), cs.getNativeGuid(), e));
        return false;
    }
    WorkflowStepCompleter.stepSucceded(stepId);
    LOGGER.info("Done Creating Service Profile : " + lsServer.getDn() + " from Service Profile Template : " + sptDn);
    return true;
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ComputeSystemControllerTimeoutException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException) MalformedURLException(java.net.MalformedURLException) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 9 with UCSServiceProfile

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

the class ComputeDeviceControllerImpl method addStepsDeactivateHost.

/**
 * Method to add required steps to deactivate a host
 *
 * @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} host URI
 * @param deactivateBootVolume
 *            boolean indicating if boot volume has to be deleted.
 * @return waitFor step name
 */
@Override
public String addStepsDeactivateHost(Workflow workflow, String waitFor, URI hostId, boolean deactivateBootVolume, List<VolumeDescriptor> volumeDescriptors) throws InternalException {
    Host host = _dbClient.queryObject(Host.class, hostId);
    if (host == null) {
        log.error("No host found with Id: {}", hostId);
        return waitFor;
    } else if (NullColumnValueGetter.isNullURI(host.getServiceProfile()) && NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        /**
         * No steps need to be added - as this was not a host that we
         * created in ViPR. If it was serviceProfile or computeElement property of the host
         * would have been set.
         */
        log.info("Host: {} has no associated serviceProfile or computeElement. So skipping service profile and boot volume deletion steps", host.getLabel());
        return waitFor;
    }
    ComputeSystem cs = null;
    if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
        UCSServiceProfile serviceProfile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
        if (serviceProfile != null) {
            cs = _dbClient.queryObject(ComputeSystem.class, serviceProfile.getComputeSystem());
            if (cs == null) {
                log.error("ServiceProfile " + serviceProfile.getDn() + " has an invalid computeSystem reference: " + serviceProfile.getComputeSystem());
                return waitFor;
            }
        }
    } else if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
        if (computeElement != null) {
            cs = _dbClient.queryObject(ComputeSystem.class, computeElement.getComputeSystem());
            if (cs == null) {
                log.error("ComputeElement " + computeElement.getDn() + " has an invalid computeSystem reference: " + computeElement.getComputeSystem());
                return waitFor;
            }
        }
    }
    if (cs == null) {
        log.error("Could not determine the Compute System the host {} is provisioned on. Skipping service profile and boot volume deletion steps", host.getLabel());
        return waitFor;
    } else {
        // TODO: need to break this up into individual smaller steps so that we can try to recover using rollback if decommission failed
        waitFor = workflow.createStep(DEACTIVATION_COMPUTE_SYSTEM_HOST, "Unbind blade from service profile", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("deactivateComputeSystemHost", cs.getId(), hostId), null, null);
        if (deactivateBootVolume && !NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
            waitFor = workflow.createStep(DEACTIVATION_COMPUTE_SYSTEM_BOOT_VOLUME_UNTAG, "Untag the boot volume for the host", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("untagBlockBootVolume", hostId, volumeDescriptors), null, null);
            waitFor = workflow.createStep(DEACTIVATION_COMPUTE_SYSTEM_BOOT_VOLUME, "Delete the boot volume for the host", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("deleteBlockBootVolume", hostId, volumeDescriptors), null, null);
        } else if (!deactivateBootVolume) {
            log.info("flag deactivateBootVolume set to false");
        } else if (!NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
            log.info("Host " + host.getLabel() + " has no bootVolume association");
        }
    }
    return waitFor;
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Example 10 with UCSServiceProfile

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

the class UcsComputeDevice method deleteServiceProfile.

/*
   * Deletes the host's service profile.
   * Determines the service profile to delete using host's serviceProfile association.
   * In case of host provisioned using pre-Anakin version of ViPR and no serviceProfile association yet set,
   * serviceprofile to delete will be determined by trying to find a serviceProfile that matches
   * the computeElement's uuid. 
   */
private void deleteServiceProfile(ComputeSystem cs, Host host) throws ClientGeneralException {
    UCSServiceProfile serviceProfile = null;
    if (host != null) {
        String spDn = null;
        if (NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
            LOGGER.info("Host has no associated service profile. cannot delete service profile.");
            return;
        } else {
            serviceProfile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
            if (serviceProfile == null) {
                LOGGER.error("Host " + host.getLabel() + " has associated serviceProfileURI: " + host.getServiceProfile() + " which is an invalid reference");
                LOGGER.info("Service profile deletion will not be triggered");
                return;
            } else {
                spDn = serviceProfile.getDn();
            }
        }
        if (spDn != null) {
            LOGGER.info("Deleting serviceProfile " + spDn);
            StringBuilder errorMessage = new StringBuilder();
            ucsmService.deleteServiceProfile(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), spDn, errorMessage);
            host.setServiceProfile(NullColumnValueGetter.getNullURI());
            host.setComputeElement(NullColumnValueGetter.getNullURI());
            _dbClient.updateObject(host);
            if (serviceProfile != null) {
                _dbClient.markForDeletion(serviceProfile);
            }
        } else {
            LOGGER.info("No service profile to delete");
        }
        // On successful deletion of the service profile - get rid of the objects that represent objects from the service profile
        LOGGER.info("Removing host endpoints");
        removeHostInitiatorsFromNetworks(host);
    } else {
        LOGGER.info("host is null. NO OP");
    }
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile)

Aggregations

UCSServiceProfile (com.emc.storageos.db.client.model.UCSServiceProfile)17 Host (com.emc.storageos.db.client.model.Host)10 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)3 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)3 URI (java.net.URI)3 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)2 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)2 ComputeSystemControllerTimeoutException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 DataObject (com.emc.storageos.db.client.model.DataObject)2 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 MalformedURLException (java.net.MalformedURLException)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ComputeBlade (com.emc.cloud.platform.ucs.out.model.ComputeBlade)1