Search in sources :

Example 21 with LsServer

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

the class UCSMServiceImpl method unbindServiceProfile.

@Override
public LsServer unbindServiceProfile(String ucsmURL, String username, String password, String spDn, StringBuilder errorMessage) throws ClientGeneralException {
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigConfMo disAssocSPFromBladeMO = new ConfigConfMo();
    disAssocSPFromBladeMO.setInHierarchical(Boolean.toString(true));
    com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
    lsServer.setDn(spDn);
    LsBinding lsBinding = new LsBinding();
    lsBinding.setPnDn("");
    lsBinding.setStatus(MO_DELETED_STATUS);
    lsServer.getContent().add(factory.createLsBinding(lsBinding));
    ConfigConfig configConfig = new ConfigConfig();
    configConfig.setManagedObject(factory.createLsServer(lsServer));
    disAssocSPFromBladeMO.getContent().add(factory.createConfigConfMoInConfig(configConfig));
    LsServer updatedLsServer = pushLsServer(computeSession, factory, disAssocSPFromBladeMO, errorMessage);
    log.info("The new Oper State of the Service Profile is : " + updatedLsServer.getOperState());
    return updatedLsServer;
}
Also used : LsBinding(com.emc.cloud.platform.ucs.in.model.LsBinding) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) ConfigConfMo(com.emc.cloud.platform.ucs.in.model.ConfigConfMo) ConfigConfig(com.emc.cloud.platform.ucs.in.model.ConfigConfig)

Example 22 with LsServer

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

the class UCSMServiceImpl method getLsServerByDn.

private LsServer getLsServerByDn(String ucsmURL, String username, String password, String spDn) throws ClientGeneralException {
    com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
    lsServer.setDn(spDn);
    LsServer lsServerOut = getManagedObject(ucsmURL, username, password, spDn, true, LsServer.class);
    if (null == lsServerOut) {
        log.error("Unable to fetch LsServer for spDn {}", spDn);
        String[] s = { "Unable to fetch LsServer for spDn " + spDn };
        throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, s);
    }
    return lsServerOut;
}
Also used : LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException)

Example 23 with LsServer

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

the class UCSMServiceImpl method getAllAssociatedLsServers.

@Override
public Map<String, LsServer> getAllAssociatedLsServers(String ucsmURL, String username, String password) throws ClientGeneralException {
    Map<String, LsServer> associatedLsServers = Collections.synchronizedMap(new HashMap<String, LsServer>());
    ;
    try {
        ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
        ConfigResolveClass configResolveClass = new ConfigResolveClass();
        configResolveClass.setClassId(NamingClassId.LS_SERVER);
        configResolveClass.setInHierarchical("true");
        // configResolveClass.getContent()
        FilterFilter inFilter = new FilterFilter();
        EqFilter eqFilter = new EqFilter();
        eqFilter.setProperty("assocState");
        eqFilter.setClazz(NamingClassId.LS_SERVER);
        eqFilter.setValue("associated");
        inFilter.setAbstractFilter(factory.createEq(eqFilter));
        configResolveClass.getContent().add(new JAXBElement<FilterFilter>(new QName("inFilter"), FilterFilter.class, inFilter));
        com.emc.cloud.platform.ucs.out.model.ConfigResolveClass configResolveClassOut = computeSession.execute(factory.createConfigResolveClass(configResolveClass), com.emc.cloud.platform.ucs.out.model.ConfigResolveClass.class);
        ConfigSet configSet = null;
        if (configResolveClassOut.getContent() != null && !configResolveClassOut.getContent().isEmpty()) {
            for (Object object : configResolveClassOut.getContent()) {
                if (object instanceof JAXBElement<?>) {
                    if (!(((JAXBElement) object).getValue() instanceof ConfigSet)) {
                        continue;
                    }
                    configSet = ((JAXBElement<ConfigSet>) object).getValue();
                    if (configSet != null && configSet.getManagedObject() != null && !configSet.getManagedObject().isEmpty()) {
                        for (JAXBElement<?> managedObject : configSet.getManagedObject()) {
                            if (managedObject.getValue() instanceof LsServer) {
                                LsServer lsServer = (LsServer) managedObject.getValue();
                                associatedLsServers.put(lsServer.getPnDn(), lsServer);
                            }
                        }
                    }
                }
            }
        }
    } catch (ClientGeneralException e) {
        log.error("Unable to get all associated lsServers", e);
        throw e;
    }
    return associatedLsServers;
}
Also used : QName(javax.xml.namespace.QName) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) ConfigResolveClass(com.emc.cloud.platform.ucs.in.model.ConfigResolveClass) JAXBElement(javax.xml.bind.JAXBElement) FilterFilter(com.emc.cloud.platform.ucs.in.model.FilterFilter) EqFilter(com.emc.cloud.platform.ucs.in.model.EqFilter) ConfigSet(com.emc.cloud.platform.ucs.out.model.ConfigSet) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException)

Example 24 with LsServer

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

the class UCSMServiceImpl method getServiceProfileTemplates.

@Override
public List<LsServer> getServiceProfileTemplates(String ucsmURL, String username, String password) throws ClientGeneralException {
    List<LsServer> serviceProfileTemplates = Collections.synchronizedList(new ArrayList<LsServer>());
    ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
    ConfigResolveClass configResolveClass = new ConfigResolveClass();
    configResolveClass.setClassId(NamingClassId.LS_SERVER);
    configResolveClass.setInHierarchical("true");
    FilterFilter inFilter = new FilterFilter();
    OrFilter orFilter = new OrFilter();
    EqFilter eqFilterInitTemplate = new EqFilter();
    eqFilterInitTemplate.setProperty("type");
    eqFilterInitTemplate.setClazz(NamingClassId.LS_SERVER);
    eqFilterInitTemplate.setValue("initial-template");
    EqFilter eqFilterUpdatingTemplate = new EqFilter();
    eqFilterUpdatingTemplate.setProperty("type");
    eqFilterUpdatingTemplate.setClazz(NamingClassId.LS_SERVER);
    eqFilterUpdatingTemplate.setValue("updating-template");
    orFilter.getAbstractFilter().add(factory.createEq(eqFilterUpdatingTemplate));
    orFilter.getAbstractFilter().add(factory.createEq(eqFilterInitTemplate));
    inFilter.setAbstractFilter(factory.createOr(orFilter));
    configResolveClass.getContent().add(new JAXBElement<FilterFilter>(new QName("inFilter"), FilterFilter.class, inFilter));
    com.emc.cloud.platform.ucs.out.model.ConfigResolveClass configResolveClassOut = computeSession.execute(factory.createConfigResolveClass(configResolveClass), com.emc.cloud.platform.ucs.out.model.ConfigResolveClass.class);
    ConfigSet configSet = null;
    if (configResolveClassOut.getContent() != null && !configResolveClassOut.getContent().isEmpty()) {
        for (Object object : configResolveClassOut.getContent()) {
            if (object instanceof JAXBElement<?>) {
                if (!(((JAXBElement) object).getValue() instanceof ConfigSet)) {
                    continue;
                }
                configSet = ((JAXBElement<ConfigSet>) object).getValue();
                if (configSet != null && configSet.getManagedObject() != null && !configSet.getManagedObject().isEmpty()) {
                    for (JAXBElement<?> managedObject : configSet.getManagedObject()) {
                        if (managedObject.getValue() instanceof LsServer) {
                            serviceProfileTemplates.add((LsServer) managedObject.getValue());
                            LsServer spt = (LsServer) managedObject.getValue();
                            log.info("SPT Name:" + spt.getName());
                        }
                    }
                }
            }
        }
    }
    return serviceProfileTemplates;
}
Also used : QName(javax.xml.namespace.QName) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) ConfigResolveClass(com.emc.cloud.platform.ucs.in.model.ConfigResolveClass) OrFilter(com.emc.cloud.platform.ucs.in.model.OrFilter) JAXBElement(javax.xml.bind.JAXBElement) FilterFilter(com.emc.cloud.platform.ucs.in.model.FilterFilter) EqFilter(com.emc.cloud.platform.ucs.in.model.EqFilter) ConfigSet(com.emc.cloud.platform.ucs.out.model.ConfigSet)

Example 25 with LsServer

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

the class UCSMServiceTest method testSetLsServerPowerState.

@Test(groups = "onDemand1")
public void testSetLsServerPowerState() throws ClientGeneralException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    Map<String, LsServer> associatedLsServers = ucsmService.getAllAssociatedLsServers(UCSM_SERVICE, UCSM_HOST_USERNAME, UCSM_HOST_PASSWORD);
    String powerStateToSet = null;
    if (associatedLsServers != null && !associatedLsServers.isEmpty()) {
        for (LsServer lsServer : associatedLsServers.values()) {
            if (SP_DN.equals(lsServer.getDn())) {
                if (lsServer.getContent() != null && !lsServer.getContent().isEmpty()) {
                    for (Object object : lsServer.getContent()) {
                        if (object instanceof JAXBElement<?>) {
                            if (((JAXBElement) object).getValue() instanceof LsPower) {
                                LsPower lsPower = ((JAXBElement<LsPower>) object).getValue();
                                if ("up".equals(lsPower.getState())) {
                                    powerStateToSet = "down";
                                } else if ("down".equals(lsPower.getState())) {
                                    powerStateToSet = "up";
                                }
                                LsServer lsServerOut = ucsmService.setLsServerPowerState(UCSM_SERVICE, UCSM_HOST_USERNAME, UCSM_HOST_PASSWORD, lsServer.getDn(), powerStateToSet, new StringBuilder());
                                if (lsServerOut.getContent() != null && !lsServerOut.getContent().isEmpty()) {
                                    for (Object object2 : lsServerOut.getContent()) {
                                        if (object2 instanceof JAXBElement<?>) {
                                            if (((JAXBElement) object2).getValue() instanceof LsPower) {
                                                LsPower lsPower2 = ((JAXBElement<LsPower>) object2).getValue();
                                                Assert.assertTrue(powerStateToSet.equals(lsPower2.getState()));
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    System.out.println("Number of associated lsServers found: " + associatedLsServers.size());
}
Also used : LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) JAXBElement(javax.xml.bind.JAXBElement) LsPower(com.emc.cloud.platform.ucs.out.model.LsPower) Test(org.testng.annotations.Test)

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