Search in sources :

Example 31 with ComputeElement

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

the class ComputeDeviceControllerImpl method createHost.

/**
 * Create host using the specified params
 *
 * @param csId
 *            {@link URI} computesystem Id
 * @param vcpoolId
 *            {@link URI} vcpoolId
 * @param varray
 *            {@link URI} varray Id
 * @param hostId
 *            {@link URI} host Id
 * @param opId
 *            (@link String} operation Id
 */
@Override
public void createHost(URI csId, URI vcpoolId, URI varray, URI hostId, String opId) throws InternalException {
    log.info("createHost");
    Host host = _dbClient.queryObject(Host.class, hostId);
    // TODO COP-28960 check for null -- host, ce, etc.
    ComputeElement ce = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
    ComputeVirtualPool vcp = _dbClient.queryObject(ComputeVirtualPool.class, vcpoolId);
    VirtualArray vArray = _dbClient.queryObject(VirtualArray.class, varray);
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, ce.getComputeSystem());
    TaskCompleter tc = new ComputeHostCompleter(hostId, opId, OperationTypeEnum.CREATE_HOST, EVENT_SERVICE_TYPE);
    getDevice(cs.getSystemType()).createHost(cs, host, vcp, vArray, tc);
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Example 32 with ComputeElement

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

the class ComputeHostCompleter method complete.

@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    Host host = dbClient.queryObject(Host.class, getId());
    ComputeElement ce = null;
    if (host != null) {
        ce = dbClient.queryObject(ComputeElement.class, host.getComputeElement());
    }
    AuditLogManager auditMgr = AuditLogManagerFactory.getAuditLogManager();
    switch(status) {
        case ready:
            if (host != null) {
                if (ce != null) {
                    host.setUuid(ce.getUuid());
                    host.setBios(ce.getBios());
                }
                host.setProvisioningStatus(ProvisioningJobStatus.COMPLETE.toString());
                dbClient.updateObject(host);
                dbClient.ready(Host.class, getId(), getOpId());
                if (ce != null) {
                    auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, host.getId().toString(), ce.getAvailable(), ce.getUuid(), ce.getDn());
                } else {
                    auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, host.getId().toString());
                }
            }
            break;
        case error:
            if (host != null) {
                host.setProvisioningStatus(ProvisioningJobStatus.ERROR.toString());
                dbClient.updateObject(host);
                dbClient.error(Host.class, getId(), getOpId(), coded);
                /**
                 * Looks like the provisioning of the Host was unsuccessful...
                 * Set the ComputeElement to available (assuming that the
                 * rollback method executed properly)
                 */
                if (ce != null) {
                    ce.setAvailable(true);
                    dbClient.updateObject(ce);
                    auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, host.getId().toString(), ce.getAvailable(), ce.getUuid(), ce.getDn());
                } else {
                    auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, host.getId().toString());
                }
            }
            break;
        default:
            throw new DeviceControllerException(new IllegalStateException("Terminal state processing called, when operation was in fact not in a terminal state!"));
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) AuditLogManager(com.emc.storageos.security.audit.AuditLogManager) Host(com.emc.storageos.db.client.model.Host) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 33 with ComputeElement

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

the class UcsComputeDevice method setSanBootTarget.

@Override
public void setSanBootTarget(ComputeSystem cs, URI computeElementId, URI hostId, URI volumeId, boolean waitForServerRestart) throws InternalException {
    ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, computeElementId);
    Map<String, Map<String, Integer>> hbaToStoragePorts = getHBAToStoragePorts(volumeId, hostId);
    // zoning map will be empty in older releases. Do we need to still continue this operation?
    try {
        if (null != computeElement) {
            StringBuilder errorMessage = new StringBuilder();
            LsServer lsServer = ucsmService.setServiceProfileToSanBoot(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getDn(), hbaToStoragePorts, errorMessage);
            if (lsServer != null) {
                if (waitForServerRestart) {
                    pullAndPollManagedObject(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getDn(), LsServer.class);
                }
            } else {
                throw new RuntimeException("Failed to set SAN boot target due to error from UCSM Service \n " + errorMessage);
            }
        } else {
            throw new RuntimeException("ComputeElement object is null for id " + computeElementId);
        }
    } catch (Exception e) {
        throw ComputeSystemControllerException.exceptions.unableToSetSanBootTarget(computeElementId.toString(), e);
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) Map(java.util.Map) HashMap(java.util.HashMap) 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 34 with ComputeElement

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

the class UcsComputeDevice method setComputeElementAttrFromBoundLsServer.

private void setComputeElementAttrFromBoundLsServer(DbClient dbClient, ComputeElement computeElement, LsServer lsServer, Host host, String systemType, boolean markUnregistered) {
    List<ComputeElementHBA> computeElementHBAs = new ArrayList<ComputeElementHBA>();
    computeElement.setUuid(lsServer.getUuid());
    computeElement.setDn(lsServer.getDn());
    String sptName = lsServer.getSrcTemplName();
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfileTemplateConstraint(computeElement.getComputeSystem()), uris);
    List<UCSServiceProfileTemplate> serviceTemplates = _dbClient.queryObject(UCSServiceProfileTemplate.class, uris, true);
    for (UCSServiceProfileTemplate serviceTemplate : serviceTemplates) {
        if (serviceTemplate.getLabel().equals(sptName)) {
            computeElement.setSptId(serviceTemplate.getId().toString());
        }
    }
    if (markUnregistered) {
        computeElement.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.UNREGISTERED.name());
    }
    computeElement.setAvailable(false);
    if (lsServer.getContent() != null && !lsServer.getContent().isEmpty()) {
        for (Serializable contentElement : lsServer.getContent()) {
            if (contentElement instanceof JAXBElement<?>) {
                if (((JAXBElement) contentElement).getValue() instanceof VnicFc) {
                    VnicFc vnicFc = (VnicFc) ((JAXBElement) contentElement).getValue();
                    ComputeElementHBA computeElementHBA = new ComputeElementHBA();
                    computeElementHBA.setComputeElement(computeElement.getId());
                    computeElementHBA.setHost(host.getId());
                    computeElementHBA.setCreationTime(Calendar.getInstance());
                    computeElementHBA.setDn(vnicFc.getDn());
                    computeElementHBA.setId(URIUtil.createId(ComputeElementHBA.class));
                    computeElementHBA.setInactive(false);
                    computeElementHBA.setLabel(vnicFc.getName());
                    computeElementHBA.setProtocol(vnicFc.getType());
                    computeElementHBA.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(computeElementHBA, systemType));
                    computeElementHBA.setNode(vnicFc.getNodeAddr());
                    computeElementHBA.setPort(vnicFc.getAddr());
                    computeElementHBA.setVsanId(getVsanIdFromvnicFC(vnicFc));
                    computeElementHBAs.add(computeElementHBA);
                }
            }
        }
    }
    if (!computeElementHBAs.isEmpty()) {
        dbClient.createObject(computeElementHBAs);
    }
    /**
     * For the case where the compute element exists, but we are updating
     * it:
     */
    if (dbClient.queryObject(ComputeElement.class, computeElement.getId()) != null) {
        dbClient.updateObject(computeElement);
    }
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) Serializable(java.io.Serializable) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) ArrayList(java.util.ArrayList) ComputeElementHBA(com.emc.storageos.db.client.model.ComputeElementHBA) JAXBElement(javax.xml.bind.JAXBElement) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VnicFc(com.emc.cloud.platform.ucs.out.model.VnicFc)

Example 35 with ComputeElement

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

the class UcsComputeDevice method unbindHostFromTemplate.

@Override
public String unbindHostFromTemplate(URI computeSystemId, URI hostId) throws InternalException {
    LOGGER.info("unbindHostFromTemplate");
    Host host = _dbClient.queryObject(Host.class, hostId);
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
    String sptDn = null;
    try {
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_069);
        // No need to check for initiators here, we are only unbinding the service profile template
        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);
            sptDn = template.getDn();
            LsServer sp = ucsmService.getLsServer(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), host.getUuid());
            if (sp != null) {
                URL ucsmURL = getUcsmURL(cs);
                StringBuilder errorMessage = new StringBuilder();
                if (null == ucsmService.unbindSPFromTemplate(ucsmURL.toString(), cs.getUsername(), cs.getPassword(), sp.getDn(), errorMessage)) {
                    LOGGER.error("Failed to unbind service profile from template due to error from UCSM Service. \n " + errorMessage.toString());
                    throw new RuntimeException("Failed to unbind service profile from template due to error from UCSM Service. \n " + errorMessage.toString());
                }
                LOGGER.info("Successfully unbound host {} from template {}", host.getLabel(), template.getLabel());
            } else {
                LOGGER.error("Unable to unbind service profile to template.  LsServer is null");
                throw new RuntimeException("Unable to unbind service profile to template.  LsServer is null");
            }
        } else {
            LOGGER.error("Unable to unbind service profile to template, due to insufficient host data.  Host or ComputeElement or host UUID is null");
            throw new RuntimeException("Unable to unbind 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 unbind service profile from template due to a exception", e);
        throw ComputeSystemControllerException.exceptions.unbindHostFromTemplateFailed(host != null ? host.getId().toString() : null, e);
    }
    return sptDn;
}
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)

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