Search in sources :

Example 1 with LsServer

use of com.emc.cloud.platform.ucs.out.model.LsServer in project coprhd-controller by CoprHD.

the class UcsComputeDevice method setNoBoot.

@Override
public void setNoBoot(ComputeSystem cs, URI computeElementId, URI hostId, boolean waitForServerRestart) throws InternalException {
    ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, computeElementId);
    try {
        if (null != computeElement) {
            StringBuilder errorMessage = new StringBuilder();
            LsServer lsServer = ucsmService.setServiceProfileToNoBoot(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getDn(), 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 no boot target due to error from UCSM Service. \n " + errorMessage.toString());
            }
        } else {
            throw new RuntimeException("ComputeElement object is null for id " + computeElementId);
        }
    } catch (Exception e) {
        throw ComputeSystemControllerException.exceptions.unableToSetNoBoot(computeElement != null ? computeElement.getLabel() : computeElementId.toString(), e);
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) 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 2 with LsServer

use of com.emc.cloud.platform.ucs.out.model.LsServer 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 3 with LsServer

use of com.emc.cloud.platform.ucs.out.model.LsServer in project coprhd-controller by CoprHD.

the class UcsComputeDevice method setLanBootTarget.

@Override
public void setLanBootTarget(ComputeSystem cs, URI computeElementId, URI hostId, boolean waitForServerRestart) throws InternalException {
    ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, computeElementId);
    try {
        if (null != computeElement) {
            StringBuilder errorMessage = new StringBuilder();
            LsServer lsServer = ucsmService.setServiceProfileToLanBoot(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getDn(), 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 LAN boot target due to error from UCSM Service \n " + errorMessage.toString());
            }
        } else {
            throw new RuntimeException("ComputeElement object is null for id " + computeElementId);
        }
    } catch (Exception e) {
        throw ComputeSystemControllerException.exceptions.unableToSetLanBoot(computeElementId.toString(), e);
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) 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 4 with LsServer

use of com.emc.cloud.platform.ucs.out.model.LsServer 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 5 with LsServer

use of com.emc.cloud.platform.ucs.out.model.LsServer in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method reconcileVhbas.

private void reconcileVhbas(ComputeSystem cs, Map<String, LsServer> associatedLsServers, VhbaHelper lookUpVsan) {
    _log.info("Reconciling Vhbas");
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeElemetsConstraint(cs.getId()), uris);
    List<ComputeElement> elements = _dbClient.queryObject(ComputeElement.class, uris, true);
    for (ComputeElement computeElement : elements) {
        Map<String, ComputeElementHBA> removeVhbas = new HashMap<>();
        Map<String, ComputeElementHBA> addVhbas = new HashMap<>();
        Map<String, ComputeElementHBA> updateVhbas = new HashMap<>();
        URIQueryResultList uriVhbas = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeElementComputeElemetHBAsConstraint(computeElement.getId()), uriVhbas);
        List<ComputeElementHBA> vbhas = _dbClient.queryObject(ComputeElementHBA.class, uriVhbas, true);
        for (ComputeElementHBA hba : vbhas) {
            removeVhbas.put(hba.getLabel(), hba);
        }
        LsServer lsServer = associatedLsServers.get(computeElement.getLabel());
        if (lsServer != null && lsServer.getContent() != null && !lsServer.getContent().isEmpty()) {
            for (Serializable contentElement : lsServer.getContent()) {
                if (contentElement instanceof JAXBElement<?> && ((JAXBElement) contentElement).getValue() instanceof VnicFc) {
                    VnicFc vnicFc = (VnicFc) ((JAXBElement) contentElement).getValue();
                    ComputeElementHBA hba = removeVhbas.get(vnicFc.getName());
                    if (hba != null) {
                        updateVhbas.put(vnicFc.getName(), hba);
                        removeVhbas.remove(hba.getLabel());
                        updateComputeElementHBA(hba, vnicFc);
                    } else {
                        hba = new ComputeElementHBA();
                        addVhbas.put(vnicFc.getName(), hba);
                        createComputeElementHBA(cs, computeElement, hba, vnicFc);
                    }
                }
            }
        }
        createDataObjects(new ArrayList<DataObject>(addVhbas.values()));
        persistDataObjects(new ArrayList<DataObject>(updateVhbas.values()));
        // Do not delete vHBAs that are still linked to the ViPR host
        Iterator<Map.Entry<String, ComputeElementHBA>> vhbaIterator = removeVhbas.entrySet().iterator();
        while (vhbaIterator.hasNext()) {
            Map.Entry<String, ComputeElementHBA> entry = vhbaIterator.next();
            if (entry.getValue().getHost() != null) {
                vhbaIterator.remove();
            } else {
                _log.info("vHBA is marked for deletion {}", entry.getKey());
            }
        }
        deleteDataObjects(new ArrayList<DataObject>(removeVhbas.values()));
    }
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) 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) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)37 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)20 ConfigConfMo (com.emc.cloud.platform.ucs.in.model.ConfigConfMo)9 ConfigConfig (com.emc.cloud.platform.ucs.in.model.ConfigConfig)9 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)9 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)9 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)9 MalformedURLException (java.net.MalformedURLException)9 HashMap (java.util.HashMap)9 ComputeSystemControllerTimeoutException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException)8 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 DataObject (com.emc.storageos.db.client.model.DataObject)7 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)7 JAXBElement (javax.xml.bind.JAXBElement)7 UCSServiceProfileTemplate (com.emc.storageos.db.client.model.UCSServiceProfileTemplate)6 ConfigSet (com.emc.cloud.platform.ucs.out.model.ConfigSet)5 Test (org.testng.annotations.Test)5 ConfigResolveClass (com.emc.cloud.platform.ucs.in.model.ConfigResolveClass)4 EqFilter (com.emc.cloud.platform.ucs.in.model.EqFilter)3