Search in sources :

Example 36 with ComputeSystem

use of com.emc.storageos.db.client.model.ComputeSystem 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 ComputeSystem

use of com.emc.storageos.db.client.model.ComputeSystem 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 38 with ComputeSystem

use of com.emc.storageos.db.client.model.ComputeSystem 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 39 with ComputeSystem

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

the class UcsDiscoveryWorker method discoverComputeSystem.

public void discoverComputeSystem(URI computeSystemURI) {
    String ucsmVersion;
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemURI);
    _log.info("Inside discoverComputeSystems of class : " + getClass().toString());
    URL ucsmURL = getUcsmURL(cs);
    List<ComputeBlade> computeBlades;
    List<LsServer> allServiceProfiles;
    Map<String, LsServer> associatedLsServers;
    List<LsServer> serviceProfileTemplates;
    List<VnicLanConnTempl> vnicTemplates;
    List<VnicSanConnTempl> vhbaTemplates;
    Map<String, FcPIo> uplinkMap;
    Map<String, SwFcSanEp> fcInterfaceMap;
    List<SwVsan> vsanList;
    Map<String, SwFcSanPc> portChannelMap;
    List<FabricVlan> vlanList;
    List<FabricVsan> vsanFabricList;
    List<com.emc.cloud.platform.ucs.out.model.LsbootPolicy> bootPolicies;
    try {
        ucsmVersion = ucsmService.getDeviceVersion(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        verifyVersion(cs, ucsmVersion);
        computeBlades = ucsmService.getComputeBlades(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        allServiceProfiles = ucsmService.getAllServiceProfiles(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        associatedLsServers = ucsmService.getAllAssociatedLsServers(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        serviceProfileTemplates = ucsmService.getServiceProfileTemplates(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        bootPolicies = ucsmService.getBootPolicies(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vnicTemplates = ucsmService.getVnicTemplates(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vhbaTemplates = ucsmService.getVhbaTemplates(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        uplinkMap = ucsmService.getFICUplinkPorts(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        fcInterfaceMap = ucsmService.getSwitchFCInterfaces(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vsanList = ucsmService.getUcsSwitchVSans(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        portChannelMap = ucsmService.getUplinkPortChannels(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vlanList = ucsmService.getUcsVlans(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vsanFabricList = ucsmService.getUcsFabricVsans(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
    } catch (Exception e) {
        _log.error("Failed to pull device data: " + cs.getId(), e);
        if (e.getCause() != null && e.getCause().getMessage() != null) {
            cs.setLastDiscoveryStatusMessage(e.getCause().getMessage());
        } else {
            cs.setLastDiscoveryStatusMessage(e.getMessage());
        }
        _dbClient.updateObject(cs);
        throw ComputeSystemControllerException.exceptions.discoverFailed(computeSystemURI.toString(), e);
    }
    try {
        reconcileServiceProfileTemplates(cs, serviceProfileTemplates);
        reconcileServiceProfiles(cs, allServiceProfiles);
        reconcileComputeBlades(cs, computeBlades, associatedLsServers);
        reconcileVhbas(cs, associatedLsServers, new VhbaHelper(vsanFabricList));
        reconcileServiceProfileTemplatesHBAs(cs, serviceProfileTemplates, new VhbaHelper(vsanFabricList));
        reconcileServiceProfileTemplatesVnics(cs, serviceProfileTemplates);
        reconcileServiceProfileTemplatesBootDefinitions(cs, serviceProfileTemplates);
        reconcileBootPolicies(cs, bootPolicies);
        reconcileVnicTemplates(cs, vnicTemplates);
        reconcileVhbaTemplates(cs, vhbaTemplates);
        Map<String, Set<String>> unpinnedVsans = getUnpinnedVSans(vsanList, fcInterfaceMap);
        reconcileUplinkPorts(cs, uplinkMap, fcInterfaceMap, unpinnedVsans);
        reconcileUplinkPortChannels(cs, portChannelMap, unpinnedVsans);
        reconcileVlans(cs, vlanList);
        associateComputeImageServer(cs);
        matchComputeBladesToHosts(cs);
        cs.setLastDiscoveryRunTime(Calendar.getInstance().getTimeInMillis());
        cs.setSuccessDiscoveryTime(Calendar.getInstance().getTimeInMillis());
        cs.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.name());
    } catch (ComputeSystemControllerException e) {
        cs.setLastDiscoveryStatusMessage(e.getMessage());
        throw ComputeSystemControllerException.exceptions.discoverFailed(cs.getId().toString(), e);
    } finally {
        _dbClient.persistObject(cs);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) ComputeBlade(com.emc.cloud.platform.ucs.out.model.ComputeBlade) FabricVsan(com.emc.cloud.platform.ucs.out.model.FabricVsan) FabricVlan(com.emc.cloud.platform.ucs.out.model.FabricVlan) URL(java.net.URL) FcPIo(com.emc.cloud.platform.ucs.out.model.FcPIo) VnicLanConnTempl(com.emc.cloud.platform.ucs.out.model.VnicLanConnTempl) SwVsan(com.emc.cloud.platform.ucs.out.model.SwVsan) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) LsbootPolicy(com.emc.cloud.platform.ucs.out.model.LsbootPolicy) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) VnicSanConnTempl(com.emc.cloud.platform.ucs.out.model.VnicSanConnTempl) SwFcSanPc(com.emc.cloud.platform.ucs.out.model.SwFcSanPc) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) MalformedURLException(java.net.MalformedURLException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) SwFcSanEp(com.emc.cloud.platform.ucs.out.model.SwFcSanEp)

Example 40 with ComputeSystem

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

the class HostService method deactivateHost.

/**
 * Deactivates the host and all its interfaces.
 *
 * @param id
 *            the URN of a ViPR Host to be deactivated
 * @param detachStorage
 *            if true, will first detach storage.
 * @param detachStorageDeprecated
 *            Deprecated. Use detachStorage instead.
 * @param deactivateBootVolume
 *            if true, and if the host was provisioned by ViPR the associated boot volume (if exists) will be
 *            deactivated
 * @brief Deactivate host
 * @return OK if deactivation completed successfully
 * @throws DatabaseException
 *             when a DB error occurs
 */
@POST
@Path("/{id}/deactivate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public TaskResourceRep deactivateHost(@PathParam("id") URI id, @DefaultValue("false") @QueryParam("detach_storage") boolean detachStorage, @DefaultValue("false") @QueryParam("detach-storage") boolean detachStorageDeprecated, @DefaultValue("true") @QueryParam("deactivate_boot_volume") boolean deactivateBootVolume) throws DatabaseException {
    Host host = queryHost(_dbClient, id);
    ArgValidator.checkEntity(host, id, true);
    boolean hasPendingTasks = hostHasPendingTasks(id);
    if (hasPendingTasks) {
        throw APIException.badRequests.resourceCannotBeDeleted("Host with another operation in progress");
    }
    boolean isHostInUse = ComputeSystemHelper.isHostInUse(_dbClient, host.getId());
    if (isHostInUse && !(detachStorage || detachStorageDeprecated)) {
        throw APIException.badRequests.resourceHasActiveReferences(Host.class.getSimpleName(), id);
    }
    UCSServiceProfile serviceProfile = null;
    if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
        serviceProfile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
        if (serviceProfile != null && !NullColumnValueGetter.isNullURI(serviceProfile.getComputeSystem())) {
            ComputeSystem ucs = _dbClient.queryObject(ComputeSystem.class, serviceProfile.getComputeSystem());
            if (ucs != null && ucs.getDiscoveryStatus().equals(DataCollectionJobStatus.ERROR.name())) {
                throw APIException.badRequests.resourceCannotBeDeleted("Host has service profile on a Compute System that failed to discover; ");
            }
        }
    }
    Collection<URI> hostIds = _dbClient.queryByType(Host.class, true);
    Collection<Host> hosts = _dbClient.queryObjectFields(Host.class, Arrays.asList("label", "uuid", "serviceProfile", "computeElement", "registrationStatus", "inactive"), ControllerUtils.getFullyImplementedCollection(hostIds));
    for (Host tempHost : hosts) {
        if (!tempHost.getId().equals(host.getId()) && !tempHost.getInactive()) {
            if (tempHost.getUuid() != null && tempHost.getUuid().equals(host.getUuid())) {
                throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same uuid " + host.getUuid() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
            }
            if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getComputeElement() == tempHost.getComputeElement()) {
                throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same computeElement " + host.getComputeElement() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
            }
            if (!NullColumnValueGetter.isNullURI(host.getServiceProfile()) && host.getServiceProfile() == tempHost.getServiceProfile()) {
                throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same serviceProfile " + host.getServiceProfile() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
            }
        }
    }
    if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
        throw APIException.badRequests.resourceCannotBeDeletedVblock(host.getLabel(), "Host " + host.getLabel() + " has a compute element, but no service profile." + " Please re-discover the Vblock Compute System and retry.");
    }
    // VBDU [DONE]: COP-28452, Running host deactivate even if initiators == null or list empty seems risky
    // If initiators are empty, we will not perform any export updates
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, ResourceOperationTypeEnum.DELETE_HOST);
    ComputeSystemController controller = getController(ComputeSystemController.class, null);
    List<VolumeDescriptor> bootVolDescriptors = new ArrayList<>();
    if (deactivateBootVolume & !NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
        Volume vol = _dbClient.queryObject(Volume.class, host.getBootVolumeId());
        if (vol.isVPlexVolume(_dbClient)) {
            bootVolDescriptors.addAll(vplexBlockServiceApiImpl.getDescriptorsForVolumesToBeDeleted(vol.getStorageController(), Arrays.asList(host.getBootVolumeId()), null));
        } else {
            if (vol.getPool() != null) {
                StoragePool storagePool = _dbClient.queryObject(StoragePool.class, vol.getPool());
                if (storagePool != null && storagePool.getStorageDevice() != null) {
                    bootVolDescriptors.add(new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, storagePool.getStorageDevice(), host.getBootVolumeId(), null, null));
                }
            }
        }
    }
    controller.detachHostStorage(host.getId(), true, deactivateBootVolume, bootVolDescriptors, taskId);
    if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        host.setProvisioningStatus(Host.ProvisioningJobStatus.IN_PROGRESS.toString());
    }
    _dbClient.persistObject(host);
    auditOp(OperationTypeEnum.DELETE_HOST, true, op.getStatus(), host.auditParameters());
    return toTask(host, taskId, op);
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) StoragePool(com.emc.storageos.db.client.model.StoragePool) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)50 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)15 URI (java.net.URI)15 Host (com.emc.storageos.db.client.model.Host)14 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)13 Produces (javax.ws.rs.Produces)13 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)12 Path (javax.ws.rs.Path)11 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)10 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)8 ComputeLanBootImagePath (com.emc.storageos.db.client.model.ComputeLanBootImagePath)7 ComputeSanBootImagePath (com.emc.storageos.db.client.model.ComputeSanBootImagePath)7 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)7 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)7 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)7 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)6 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)6 MalformedURLException (java.net.MalformedURLException)6 POST (javax.ws.rs.POST)6 URL (java.net.URL)5