Search in sources :

Example 36 with ComputeElement

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

the class UcsComputeDevice method changePowerState.

private void changePowerState(URI csId, URI ceId, String state) throws DeviceControllerException {
    LOGGER.info("changePowerState");
    ComputeElement ce = _dbClient.queryObject(ComputeElement.class, ceId);
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, csId);
    OperationTypeEnum typeEnum = POWER_DOWN.equals(state) ? OperationTypeEnum.POWERDOWN_COMPUTE_ELEMENT : OperationTypeEnum.POWERUP_COMPUTE_ELEMENT;
    try {
        URL ucsmURL = getUcsmURL(cs);
        StringBuilder errorMessage = new StringBuilder();
        ucsmService.setLsServerPowerState(ucsmURL.toString(), cs.getUsername(), cs.getPassword(), ce.getDn(), state, errorMessage);
        pullAndPollManagedObject(ucsmURL.toString(), cs.getUsername(), cs.getPassword(), ce.getLabel(), ComputeBlade.class);
    } catch (ComputeSystemControllerTimeoutException cstoe) {
        LOGGER.error("Unable to change power state of compute element due to a device TimeOut", cstoe);
        throw cstoe;
    } catch (Exception e) {
        LOGGER.error("Unable to change power state of compute element due to a exception", e);
        throw ComputeSystemControllerException.exceptions.powerStateChangeFailed(state, ce != null ? ce.getId().toString() : null, e);
    }
    _auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE_CE, typeEnum, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, ce.getId().toString(), ce.getLabel(), ce.getNativeGuid(), ce.getUuid(), ce.getOriginalUuid());
}
Also used : ComputeSystemControllerTimeoutException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) URL(java.net.URL) 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 37 with ComputeElement

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

the class UcsComputeDevice method bindServiceProfileToBlade.

public void bindServiceProfileToBlade(ComputeSystem computeSystem, URI hostURI, String contextStepId, String stepId) {
    ComputeElement computeElement = null;
    LsServer serviceProfile = null;
    String spDn = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        spDn = (String) workflowService.loadStepData(contextStepId);
        if (spDn == null) {
            throw new IllegalStateException("Invalid value for step data. Previous step didn't persist required data.");
        }
        Host host = _dbClient.queryObject(Host.class, hostURI);
        computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
        if (computeElement != null) {
            LOGGER.info("Binding Service Profile : " + spDn + " to blade : " + computeElement.getLabel());
            StringBuilder errorMessage = new StringBuilder();
            serviceProfile = ucsmService.bindSPToComputeElement(getUcsmURL(computeSystem).toString(), computeSystem.getUsername(), computeSystem.getPassword(), spDn, computeElement.getLabel(), errorMessage);
            serviceProfile = pullAndPollManagedObject(getUcsmURL(computeSystem).toString(), computeSystem.getUsername(), computeSystem.getPassword(), spDn, LsServer.class);
            // Test mechanism to invoke a failure. No-op on production
            // systems.
            InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_063);
            if (serviceProfile == null || ASSOC_STATE_UNASSOCIATED.equals(serviceProfile.getAssocState())) {
                String additionalInfo = null;
                if (serviceProfile != null) {
                    additionalInfo = "\n \t Additional info from UCS: \n \t ConfigState: " + serviceProfile.getConfigState() + " ConfigQualifier:" + serviceProfile.getConfigQualifier();
                }
                LOGGER.info("SP {} AssocState is marked unassociated or null. Bind ServiceProfileToBlade failed. ConfigState: {} , ConfigQualifer: {}", spDn, (serviceProfile == null ? "" : serviceProfile.getConfigState()), (serviceProfile == null ? "" : serviceProfile.getConfigQualifier()));
                throw new RuntimeException("Failed to bind service profile " + spDn + " to blade " + computeElement.getLabel() + " picked from compute virtual pool." + "\n \t ServiceProfile state is " + (serviceProfile == null ? "null" : serviceProfile.getAssocState()) + "\n \t " + errorMessage.toString() + additionalInfo);
            }
            // Test mechanism to invoke a failure. No-op on production
            // systems.
            InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_064);
            setComputeElementAttrFromBoundLsServer(_dbClient, computeElement, serviceProfile, host, computeSystem.getSystemType(), false);
            LOGGER.info("Done binding Service Profile : " + spDn + " to blade : " + computeElement.getLabel());
            WorkflowStepCompleter.stepSucceded(stepId);
        } else {
            LOGGER.info("Unable to associate computeElement and LsServer/serviceProfile attribute.  ComputeElement is null.");
            throw new RuntimeException(BIND_SERVICE_PROFILE_TO_BLADE_STEP + " failed.");
        }
    } catch (Exception e) {
        LOGGER.error("Step : " + BIND_SERVICE_PROFILE_TO_BLADE_STEP + " Failed...", e);
        WorkflowStepCompleter.stepFailed(stepId, ComputeSystemControllerException.exceptions.unableToProvisionHost(spDn, computeSystem.getNativeGuid(), e));
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) Host(com.emc.storageos.db.client.model.Host) 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 38 with ComputeElement

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

the class UcsComputeDevice method rebindHostToTemplate.

@Override
public void rebindHostToTemplate(URI computeSystemId, URI hostId) throws InternalException {
    LOGGER.info("rebindHostToTemplate");
    // re-bind host to SPT
    Host host = _dbClient.queryObject(Host.class, hostId);
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
    try {
        if (host != null && !NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getUuid() != null) {
            ComputeElement ce = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
            URI sptId = URI.create(ce.getSptId());
            UCSServiceProfileTemplate template = _dbClient.queryObject(UCSServiceProfileTemplate.class, sptId);
            LsServer sp = ucsmService.getLsServer(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), host.getUuid());
            if (sp != null && template.getLabel() != null) {
                if (!sp.getSrcTemplName().equalsIgnoreCase(template.getLabel())) {
                    StringBuilder errorMessage = new StringBuilder();
                    URL ucsmURL = getUcsmURL(cs);
                    if (null == ucsmService.bindSPToTemplate(ucsmURL.toString(), cs.getUsername(), cs.getPassword(), sp.getDn(), template.getLabel(), errorMessage)) {
                        throw new RuntimeException("Failed to rebind service profile to template. \n " + errorMessage.toString());
                    }
                    LOGGER.info("Successfully rebound host {} to template {}", host.getLabel(), template.getLabel());
                } else {
                    LOGGER.info("Host is already bound to template, nothing to do.  No OP.");
                }
            } else {
                LOGGER.error("Unable to bind service profile to template.  LsServer or UCSServiceProfileTemplate is null");
                throw new RuntimeException("Unable to bind service profile to template.  LsServer or UCSServiceProfileTemplate is null");
            }
        } else {
            LOGGER.error("Unable to bind service profile to template, due to insufficient host data.  Host or ComputeElement or host UUID is null");
            throw new RuntimeException("Unable to bind service profile to template, due to insufficient host data.  Host or host's computeElement or host UUID is null");
        }
    } catch (Exception e) {
        LOGGER.error("Unable to bind service profile to template due to a exception", e);
        throw ComputeSystemControllerException.exceptions.bindHostToTemplateFailed(host != null ? host.getId().toString() : null, e);
    }
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) URL(java.net.URL) 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 39 with ComputeElement

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

the class UcsComputeDevice method removeOsInstallNetwork.

@Override
public void removeOsInstallNetwork(URI computeSystemId, URI computeElementId, Map<String, Boolean> vlanMap) throws InternalException {
    LOGGER.info("removeOsInstallNetwork");
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
    ComputeElement ce = _dbClient.queryObject(ComputeElement.class, computeElementId);
    String osInstallVlan = cs.getOsInstallNetwork();
    try {
        ucsmService.removeOsInstallVlan(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), ce.getDn(), osInstallVlan, vlanMap);
    } catch (ClientGeneralException e) {
        LOGGER.error("Unable to set os install vlan: " + cs.getOsInstallNetwork() + " On computeElement : " + ce.getId(), e);
        throw ComputeSystemControllerException.exceptions.unableToRemoveOsInstallNetwork(osInstallVlan, ce.getId().toString(), e);
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException)

Example 40 with ComputeElement

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

the class UcsComputeDevice method deleteLsServer.

public void deleteLsServer(ComputeSystem cs, URI hostURI, String createSpStepId, String stepId) throws ClientGeneralException {
    WorkflowStepCompleter.stepExecuting(stepId);
    String spDn = null;
    try {
        Host host = _dbClient.queryObject(Host.class, hostURI);
        UCSServiceProfile profile = null;
        if (host != null) {
            if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
                profile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
                if (profile == null) {
                    throw ComputeSystemControllerException.exceptions.invalidServiceProfileReference(host.getServiceProfile().toString());
                } else {
                    spDn = profile.getDn();
                    if (spDn != null) {
                        LOGGER.info("Deleting Service Profile : " + spDn);
                        // Test mechanism to invoke a failure. No-op on production systems.
                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_066);
                        StringBuilder errorMessage = new StringBuilder();
                        ucsmService.deleteServiceProfile(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), spDn, errorMessage);
                        LOGGER.info("Done Deleting Service Profile : " + spDn);
                        _dbClient.markForDeletion(profile);
                        host.setServiceProfile(NullColumnValueGetter.getNullURI());
                    } else {
                        throw ComputeSystemControllerException.exceptions.invalidServiceProfile(host.getServiceProfile().toString());
                    }
                }
            }
            if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
                ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
                if (computeElement != null) {
                    computeElement.setAvailable(true);
                    computeElement.setUuid(computeElement.getOriginalUuid());
                    _dbClient.updateObject(computeElement);
                }
                host.setComputeElement(NullColumnValueGetter.getNullURI());
            }
            _dbClient.updateObject(host);
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception e) {
        LOGGER.error("Unable to deleteLsServer...", e);
        WorkflowStepCompleter.stepFailed(stepId, ComputeSystemControllerException.exceptions.unableToProvisionHost(spDn, cs.getNativeGuid(), e));
    }
}
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) 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)

Aggregations

ComputeElement (com.emc.storageos.db.client.model.ComputeElement)52 Host (com.emc.storageos.db.client.model.Host)24 URI (java.net.URI)20 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)11 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)10 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)10 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)9 MalformedURLException (java.net.MalformedURLException)9 Produces (javax.ws.rs.Produces)9 ComputeSystemControllerTimeoutException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException)8 HashMap (java.util.HashMap)8 Path (javax.ws.rs.Path)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7 ComputeVirtualPool (com.emc.storageos.db.client.model.ComputeVirtualPool)6 UCSServiceProfile (com.emc.storageos.db.client.model.UCSServiceProfile)6 UCSServiceProfileTemplate (com.emc.storageos.db.client.model.UCSServiceProfileTemplate)6 Cluster (com.emc.storageos.db.client.model.Cluster)4