Search in sources :

Example 31 with LsServer

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

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

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

the class UcsDiscoveryWorker method reconcileServiceProfileTemplatesBootDefinitions.

private void reconcileServiceProfileTemplatesBootDefinitions(ComputeSystem cs, List<LsServer> lsServers) {
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfileTemplateConstraint(cs.getId()), uris);
    Map<String, LsServer> lsServerMap = new HashMap<>();
    for (LsServer lsServer : lsServers) {
        lsServerMap.put(lsServer.getDn(), lsServer);
    }
    List<UCSServiceProfileTemplate> serviceTemplates = _dbClient.queryObject(UCSServiceProfileTemplate.class, uris, true);
    for (UCSServiceProfileTemplate serviceProfileTemplate : serviceTemplates) {
        LsServer lsServer = lsServerMap.get(serviceProfileTemplate.getDn());
        if (lsServer == null) {
            continue;
        }
        Map<String, Object> serviceProfileTemplateDetails = getServiceProfileTemplateDetails(lsServer);
        LsbootDef lsbootDef = (LsbootDef) serviceProfileTemplateDetails.get("associatedBootPolicy");
        if (lsbootDef != null) {
            _log.debug("Reconcile bootdef for SPT:" + serviceProfileTemplate.getLabel());
            ComputeBootDef computeBootDef = reconcileComputeBootDef(lsbootDef, serviceProfileTemplate, cs);
        } else {
            // Remove any computeBootDefs that are no longer needed.
            URIQueryResultList bootDefUris = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getServiceProfileTemplateComputeBootDefsConstraint(serviceProfileTemplate.getId()), bootDefUris);
            List<ComputeBootDef> bootDefs = _dbClient.queryObject(ComputeBootDef.class, bootDefUris, true);
            deleteComputeBootDefs(bootDefs);
        }
    }
}
Also used : UCSServiceProfileTemplate(com.emc.storageos.db.client.model.UCSServiceProfileTemplate) ComputeBootDef(com.emc.storageos.db.client.model.ComputeBootDef) HashMap(java.util.HashMap) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) DiscoveredSystemObject(com.emc.storageos.db.client.model.DiscoveredSystemObject) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) LsbootDef(com.emc.cloud.platform.ucs.out.model.LsbootDef) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 34 with LsServer

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

the class UcsDiscoveryWorker method reconcileServiceProfiles.

private void reconcileServiceProfiles(ComputeSystem cs, List<LsServer> allLsServers) {
    _log.info("Reconciling UCS Service Profiles");
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfilesConstraint(cs.getId()), uris);
    Map<String, UCSServiceProfile> removeServiceProfiles = new HashMap<>();
    Map<String, UCSServiceProfile> updateServiceProfiles = new HashMap<>();
    Map<String, UCSServiceProfile> addServiceProfiles = new HashMap<>();
    List<UCSServiceProfile> serviceProfiles = _dbClient.queryObject(UCSServiceProfile.class, uris, true);
    for (UCSServiceProfile serviceProfile : serviceProfiles) {
        removeServiceProfiles.put(serviceProfile.getDn(), serviceProfile);
    }
    // discovered data
    for (LsServer lsServer : filterLsServers(allLsServers)) {
        UCSServiceProfile serviceProfile = removeServiceProfiles.get(lsServer.getDn());
        if (serviceProfile != null) {
            removeServiceProfiles.remove(lsServer.getDn());
            updateUCSServiceProfile(serviceProfile, lsServer);
            updateServiceProfiles.put(lsServer.getDn(), serviceProfile);
        } else {
            serviceProfile = new UCSServiceProfile();
            createUCSServiceProfile(cs, serviceProfile, lsServer);
            addServiceProfiles.put(lsServer.getDn(), serviceProfile);
        }
    }
    createDataObjects(new ArrayList<DataObject>(addServiceProfiles.values()));
    persistDataObjects(new ArrayList<DataObject>(updateServiceProfiles.values()));
    if (!removeServiceProfiles.isEmpty()) {
        for (String key : removeServiceProfiles.keySet()) {
            _log.info("Marked for deletion UCSServiceProfile: " + key);
        }
        removeServiceProfilesFromHosts(removeServiceProfiles.values());
        deleteDataObjects(new ArrayList<DataObject>(removeServiceProfiles.values()));
    }
    validateServiceProfileUuids(cs);
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) HashMap(java.util.HashMap) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 35 with LsServer

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

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