Search in sources :

Example 96 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList 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)

Example 97 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method reconcileComputeBootDef.

private ComputeBootDef reconcileComputeBootDef(LsbootDef lsBootDef, UCSServiceProfileTemplate spt, ComputeSystem cs) {
    ComputeBootDef bootDef = null;
    URIQueryResultList bootDefUris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getServiceProfileTemplateComputeBootDefsConstraint(spt.getId()), bootDefUris);
    List<ComputeBootDef> bootDefs = _dbClient.queryObject(ComputeBootDef.class, bootDefUris, true);
    if (!bootDefs.isEmpty()) {
        bootDef = bootDefs.get(0);
        bootDef.setComputeSystem(cs.getId());
        bootDef.setServiceProfileTemplate(spt.getId());
        // bootDef.setDn(lsBootDef.getDn());
        if (lsBootDef.getEnforceVnicName().equals("yes")) {
            bootDef.setEnforceVnicVhbaNames(true);
        } else {
            bootDef.setEnforceVnicVhbaNames(false);
        }
        _dbClient.persistObject(bootDef);
    }
    if (bootDef == null) {
        bootDef = new ComputeBootDef();
        URI uri = URIUtil.createId(ComputeBootDef.class);
        bootDef.setId(uri);
        bootDef.setComputeSystem(cs.getId());
        bootDef.setServiceProfileTemplate(spt.getId());
        // bootDef.setDn(lsBootDef.getDn());
        if (lsBootDef.getEnforceVnicName().equals("yes")) {
            bootDef.setEnforceVnicVhbaNames(true);
        } else {
            bootDef.setEnforceVnicVhbaNames(false);
        }
        _dbClient.createObject(bootDef);
    }
    ComputeSanBoot sanBoot = null;
    ComputeLanBoot lanBoot = null;
    URIQueryResultList sanBootUris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeBootDefComputeSanBootConstraint(bootDef.getId()), sanBootUris);
    List<ComputeSanBoot> sanBootList = _dbClient.queryObject(ComputeSanBoot.class, sanBootUris, true);
    if (sanBootList != null && !sanBootList.isEmpty()) {
        sanBoot = sanBootList.get(0);
    }
    URIQueryResultList lanBootUris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeBootDefComputeLanBootConstraint(bootDef.getId()), lanBootUris);
    List<ComputeLanBoot> lanBootList = _dbClient.queryObject(ComputeLanBoot.class, lanBootUris, true);
    if (lanBootList != null && !lanBootList.isEmpty()) {
        lanBoot = lanBootList.get(0);
    }
    boolean hasLanBoot = false;
    boolean hasSanBoot = false;
    Integer nonSanBootOrder = null;
    Integer sanBootOrder = null;
    if (lsBootDef.getContent() != null && !lsBootDef.getContent().isEmpty()) {
        for (Serializable element : lsBootDef.getContent()) {
            if (element instanceof JAXBElement<?>) {
                if (((JAXBElement) element).getValue() instanceof LsbootLan) {
                    LsbootLan lsbootLan = (LsbootLan) ((JAXBElement) element).getValue();
                    lanBoot = reconcileComputeLanBoot(lsbootLan, lanBoot, bootDef, null);
                    hasLanBoot = true;
                    Integer order = Integer.parseInt(lsbootLan.getOrder());
                    if (nonSanBootOrder == null) {
                        nonSanBootOrder = order;
                    } else if (order < nonSanBootOrder) {
                        nonSanBootOrder = order;
                    }
                } else if (((JAXBElement) element).getValue() instanceof LsbootStorage) {
                    LsbootStorage lsbootStorage = (LsbootStorage) ((JAXBElement) element).getValue();
                    sanBoot = reconcileComputeSanBoot(lsbootStorage, sanBoot, bootDef, null);
                    hasSanBoot = true;
                    sanBootOrder = Integer.parseInt(lsbootStorage.getOrder());
                } else if (((JAXBElement) element).getValue() instanceof LsbootSan) {
                    LsbootSan lsbootSan = (LsbootSan) ((JAXBElement) element).getValue();
                    sanBoot = reconcileComputeSanBoot(lsbootSan, sanBoot, bootDef, null);
                    hasSanBoot = true;
                    sanBootOrder = Integer.parseInt(lsbootSan.getOrder());
                } else if (((JAXBElement) element).getValue() instanceof LsbootVirtualMedia) {
                    LsbootVirtualMedia lsbootVirtualMedia = (LsbootVirtualMedia) ((JAXBElement) element).getValue();
                    Integer order = Integer.parseInt(lsbootVirtualMedia.getOrder());
                    if (nonSanBootOrder == null) {
                        nonSanBootOrder = order;
                    } else if (order < nonSanBootOrder) {
                        nonSanBootOrder = order;
                    }
                } else if (((JAXBElement) element).getValue() instanceof LsbootIScsi) {
                    LsbootIScsi lsbootIScsi = (LsbootIScsi) ((JAXBElement) element).getValue();
                    Integer order = Integer.parseInt(lsbootIScsi.getOrder());
                    if (nonSanBootOrder == null) {
                        nonSanBootOrder = order;
                    } else if (order < nonSanBootOrder) {
                        nonSanBootOrder = order;
                    }
                }
            }
        }
    }
    if (hasSanBoot && nonSanBootOrder != null) {
        sanBoot = (ComputeSanBoot) _dbClient.queryObject(sanBoot.getId());
        if (nonSanBootOrder < sanBootOrder) {
            sanBoot.setIsFirstBootDevice(false);
        } else {
            sanBoot.setIsFirstBootDevice(true);
        }
        _dbClient.persistObject(sanBoot);
    }
    if (!hasSanBoot && sanBoot != null) {
        List<ComputeSanBoot> sanBoots = new ArrayList<ComputeSanBoot>();
        sanBoots.add(sanBoot);
        deleteComputeSanBoot(sanBoots);
    }
    if (!hasLanBoot && lanBoot != null) {
        List<ComputeLanBoot> lanBoots = new ArrayList<ComputeLanBoot>();
        lanBoots.add(lanBoot);
        deleteComputeLanBoot(lanBoots);
    }
    return bootDef;
}
Also used : Serializable(java.io.Serializable) LsbootVirtualMedia(com.emc.cloud.platform.ucs.out.model.LsbootVirtualMedia) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ComputeLanBoot(com.emc.storageos.db.client.model.ComputeLanBoot) LsbootSan(com.emc.cloud.platform.ucs.out.model.LsbootSan) ComputeBootDef(com.emc.storageos.db.client.model.ComputeBootDef) ComputeSanBoot(com.emc.storageos.db.client.model.ComputeSanBoot) LsbootLan(com.emc.cloud.platform.ucs.out.model.LsbootLan) LsbootStorage(com.emc.cloud.platform.ucs.out.model.LsbootStorage) LsbootIScsi(com.emc.cloud.platform.ucs.out.model.LsbootIScsi)

Example 98 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method reconcileUplinkPorts.

private void reconcileUplinkPorts(ComputeSystem cs, Map<String, FcPIo> uplinkMap, Map<String, SwFcSanEp> fcInterfaceMap, Map<String, Set<String>> unpinnedVsans) {
    _log.info("Reconciling FIC uplink ports");
    Map<String, ComputeFabricUplinkPort> removePorts = new HashMap<>();
    Map<String, ComputeFabricUplinkPort> updatePorts = new HashMap<>();
    Map<String, ComputeFabricUplinkPort> addPorts = new HashMap<>();
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeFabricUplinkPortConstraint(cs.getId()), uris);
    List<ComputeFabricUplinkPort> uplinkPorts = _dbClient.queryObject(ComputeFabricUplinkPort.class, uris, true);
    for (ComputeFabricUplinkPort port : uplinkPorts) {
        removePorts.put(port.getDn(), port);
    }
    // discovered data
    for (FcPIo fcPIo : uplinkMap.values()) {
        ComputeFabricUplinkPort cfup = removePorts.get(fcPIo.getDn());
        if (cfup != null) {
            updatePorts.put(fcPIo.getDn(), cfup);
            removePorts.remove(fcPIo.getDn());
            updateUplinkPorts(cfup, fcPIo, fcInterfaceMap, unpinnedVsans);
        } else {
            cfup = new ComputeFabricUplinkPort();
            addPorts.put(fcPIo.getDn(), cfup);
            createUplinkPorts(cs, cfup, fcPIo, fcInterfaceMap, unpinnedVsans);
        }
    }
    createDataObjects(new ArrayList<DataObject>(addPorts.values()));
    persistDataObjects(new ArrayList<DataObject>(updatePorts.values()));
    deleteDataObjects(new ArrayList<DataObject>(removePorts.values()));
}
Also used : FcPIo(com.emc.cloud.platform.ucs.out.model.FcPIo) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) ComputeFabricUplinkPort(com.emc.storageos.db.client.model.ComputeFabricUplinkPort) HashMap(java.util.HashMap) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 99 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method deleteComputeLanBoot.

private void deleteComputeLanBoot(List<ComputeLanBoot> lanBootList) {
    List<ComputeLanBoot> removeLanBoots = new ArrayList<ComputeLanBoot>();
    for (ComputeLanBoot lanBoot : lanBootList) {
        URIQueryResultList lanImageUris = new URIQueryResultList();
        _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeLanBootImagePathsConstraint(lanBoot.getId()), lanImageUris);
        List<ComputeLanBootImagePath> lanBootPathList = _dbClient.queryObject(ComputeLanBootImagePath.class, lanImageUris, true);
        if (lanBootPathList != null && !lanBootPathList.isEmpty()) {
            deleteComputeLanBootImagePaths(lanBootPathList);
        }
        removeLanBoots.add(lanBoot);
    }
    deleteDataObjects(new ArrayList<DataObject>(removeLanBoots));
}
Also used : ComputeLanBoot(com.emc.storageos.db.client.model.ComputeLanBoot) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) ComputeLanBootImagePath(com.emc.storageos.db.client.model.ComputeLanBootImagePath) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 100 with URIQueryResultList

use of com.emc.storageos.db.client.constraint.URIQueryResultList in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method reconcileComputeSanBootImage.

private ComputeSanBootImage reconcileComputeSanBootImage(LsbootSanImage sanImage, ComputeSanBootImage computeSanImage, ComputeSanBoot sanBoot) {
    if (computeSanImage != null) {
        computeSanImage.setDn(sanImage.getDn());
        computeSanImage.setVnicName(sanImage.getVnicName());
        _dbClient.persistObject(computeSanImage);
    }
    if (computeSanImage == null) {
        computeSanImage = new ComputeSanBootImage();
        URI uriSanBootImage = URIUtil.createId(ComputeSanBootImage.class);
        computeSanImage.setId(uriSanBootImage);
        computeSanImage.setType(sanImage.getType());
        computeSanImage.setVnicName(sanImage.getVnicName());
        computeSanImage.setDn(sanImage.getDn());
        computeSanImage.setComputeSanBoot(sanBoot.getId());
        _dbClient.createObject(computeSanImage);
    }
    Map<String, ComputeSanBootImagePath> computeSanBootImagePathMap = new HashMap<String, ComputeSanBootImagePath>();
    URIQueryResultList sanImagePathUris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSanBootImagePathConstraint(computeSanImage.getId()), sanImagePathUris);
    List<ComputeSanBootImagePath> sanBootPathList = _dbClient.queryObject(ComputeSanBootImagePath.class, sanImagePathUris, true);
    if (sanBootPathList != null && !sanBootPathList.isEmpty()) {
        for (ComputeSanBootImagePath sanBootImagePath : sanBootPathList) {
            computeSanBootImagePathMap.put(sanBootImagePath.getType(), sanBootImagePath);
        }
    }
    if (sanImage.getContent() != null && !sanImage.getContent().isEmpty()) {
        for (Serializable e2 : sanImage.getContent()) {
            if (e2 instanceof JAXBElement<?>) {
                if (((JAXBElement) e2).getValue() instanceof LsbootSanImagePath) {
                    LsbootSanImagePath lsSanImagePath = (LsbootSanImagePath) ((JAXBElement) e2).getValue();
                    ComputeSanBootImagePath sanBootImagePath = computeSanBootImagePathMap.get(lsSanImagePath.getType());
                    computeSanBootImagePathMap.remove(lsSanImagePath.getType());
                    sanBootImagePath = reconcileComputeSanBootImagePath(lsSanImagePath, sanBootImagePath, computeSanImage);
                }
            }
        }
    }
    deleteComputeSanBootImagePaths(new ArrayList<ComputeSanBootImagePath>(computeSanBootImagePathMap.values()));
    return computeSanImage;
}
Also used : ComputeSanBootImagePath(com.emc.storageos.db.client.model.ComputeSanBootImagePath) LsbootSanImagePath(com.emc.cloud.platform.ucs.out.model.LsbootSanImagePath) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ComputeSanBootImage(com.emc.storageos.db.client.model.ComputeSanBootImage) JAXBElement(javax.xml.bind.JAXBElement) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)664 URI (java.net.URI)497 ArrayList (java.util.ArrayList)258 HashMap (java.util.HashMap)107 Volume (com.emc.storageos.db.client.model.Volume)97 NamedURI (com.emc.storageos.db.client.model.NamedURI)96 HashSet (java.util.HashSet)92 StoragePort (com.emc.storageos.db.client.model.StoragePort)91 StringSet (com.emc.storageos.db.client.model.StringSet)83 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)64 Produces (javax.ws.rs.Produces)55 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)54 Path (javax.ws.rs.Path)54 List (java.util.List)53 StoragePool (com.emc.storageos.db.client.model.StoragePool)49 Initiator (com.emc.storageos.db.client.model.Initiator)47 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)45 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)39 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)38