Search in sources :

Example 1 with ScaleIOSDC

use of com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC in project coprhd-controller by CoprHD.

the class StorageSystemDataCollectionService method discoverScaleIO.

/**
 * Collect Data for ScaleIO system
 *
 * @param param ScaleIO discovery information
 * @return Data collected for ScaleIO system
 */
@POST
@Path("/scaleio")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public ScaleIOSystemDataRestRep discoverScaleIO(ScaleIOCollectDataParam param) {
    log.debug("discovering ScaleIO: {}", param.getIPAddress());
    URI baseURI = URI.create(ScaleIOConstants.getAPIBaseURI(param.getIPAddress(), param.getPortNumber()));
    ScaleIORestClient client = (ScaleIORestClient) scaleIORestClientFactory.getRESTClient(baseURI, param.getUserName(), param.getPassword());
    ScaleIOSystemDataRestRep sio = null;
    try {
        // collect and map scaleIO system
        ScaleIOSystem system = client.getSystem();
        sio = ScaleIODataMapper.map(system);
        // collect sds,device,fault set, and protection domain data
        List<ScaleIOSDS> allSDS = client.queryAllSDS();
        Map<String, ScaleIOProtectionDomain> pdMap = null;
        List<ScaleIOProtectionDomain> pdList = client.getProtectionDomains();
        if (null != pdList) {
            pdMap = pdList.stream().collect(Collectors.toMap(ScaleIOProtectionDomain::getId, p -> p));
        }
        List<ScaleIOFaultSet> fsList = client.queryAllFaultSets();
        Map<String, ScaleIOFaultSet> fsMap = null;
        if (null != fsList) {
            fsMap = client.queryAllFaultSets().stream().collect(Collectors.toMap(ScaleIOFaultSet::getId, f -> f));
        }
        Map<String, ScaleIOStoragePool> spMap = client.queryAllStoragePools().stream().collect(Collectors.toMap(ScaleIOStoragePool::getId, s -> s));
        // map SDS data
        List<ScaleIOSDSDataRestRep> scaleIOSDSDataRestReps = new ArrayList<ScaleIOSDSDataRestRep>();
        for (ScaleIOSDS sds : allSDS) {
            ScaleIOSDSDataRestRep sdsData = ScaleIODataMapper.map(sds);
            // map device data
            List<ScaleIODevice> devices = client.getSdsDevices(sds.getId());
            List<ScaleIODeviceDataRestRep> scaleIODeviceDataRestReps = new ArrayList<ScaleIODeviceDataRestRep>();
            if (null != devices) {
                for (ScaleIODevice device : devices) {
                    ScaleIODeviceDataRestRep scaleIODeviceDataRestRep = ScaleIODataMapper.map(device);
                    // map storagepool data
                    scaleIODeviceDataRestRep.setStoragePool(ScaleIODataMapper.map(spMap.get(device.getStoragePoolId())));
                    scaleIODeviceDataRestReps.add(scaleIODeviceDataRestRep);
                }
                sdsData.setDevices(scaleIODeviceDataRestReps);
            }
            // map fault set data
            if (null != fsMap) {
                sdsData.setFaultSet(ScaleIODataMapper.map(fsMap.get(sds.getFaultSetId())));
            }
            // map protection domain and IP data
            if (null != pdMap) {
                sdsData.setProtectionDomain(ScaleIODataMapper.map(pdMap.get(sds.getProtectionDomainId())));
            }
            sdsData.setIpList(ScaleIODataMapper.mapIpList(sds.getIpList()));
            scaleIOSDSDataRestReps.add(sdsData);
        }
        sio.setSdsList(scaleIOSDSDataRestReps);
        // collect and map SDC data
        List<ScaleIOSDC> allSDC = client.queryAllSDC();
        List<ScaleIOSDCDataRestRep> scaleIOSDCDataRestReps = new ArrayList<ScaleIOSDCDataRestRep>();
        for (ScaleIOSDC sdc : allSDC) {
            ScaleIOSDCDataRestRep sdcData = ScaleIODataMapper.map(sdc);
            // map device data
            List<ScaleIOVolume> volumes = client.getSdcVolumes(sdc.getId());
            List<ScaleIOVolumeDataRestRep> scaleIOVolumeDataRestReps = new ArrayList<ScaleIOVolumeDataRestRep>();
            if (null != volumes) {
                for (ScaleIOVolume volume : volumes) {
                    ScaleIOVolumeDataRestRep scaleIOVolumeDataRestRep = ScaleIODataMapper.map(volume);
                    // map storagepool data
                    scaleIOVolumeDataRestRep.setStoragePool(ScaleIODataMapper.map(spMap.get(volume.getStoragePoolId())));
                    scaleIOVolumeDataRestReps.add(scaleIOVolumeDataRestRep);
                }
                sdcData.setVolumes(scaleIOVolumeDataRestReps);
            }
            scaleIOSDCDataRestReps.add(sdcData);
        }
        sio.setSdcList(scaleIOSDCDataRestReps);
    } catch (ScaleIOException e) {
        log.error(String.format("Exception was encountered in the ScaleIO client when connecting to instance %s", param.getIPAddress()), e);
        throw APIException.badRequests.storageSystemClientException(SCALEIO, e.getLocalizedMessage());
    } catch (JSONException e) {
        log.error(String.format("Exception was encountered when attempting to discover ScaleIO Instance %s", param.getIPAddress()), e);
        throw APIException.badRequests.cannotDiscoverStorageSystemUnexpectedResponse(SCALEIO);
    }
    return sio;
}
Also used : ScaleIOFaultSet(com.emc.storageos.scaleio.api.restapi.response.ScaleIOFaultSet) Role(com.emc.storageos.security.authorization.Role) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ScaleIOSDCDataRestRep(com.emc.storageos.model.collectdata.ScaleIOSDCDataRestRep) ScaleIOSystemDataRestRep(com.emc.storageos.model.collectdata.ScaleIOSystemDataRestRep) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) ScaleIOCollectDataParam(com.emc.storageos.model.collectdata.ScaleIOCollectDataParam) ArrayList(java.util.ArrayList) ScaleIOProtectionDomain(com.emc.storageos.scaleio.api.restapi.response.ScaleIOProtectionDomain) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) URI(java.net.URI) ScaleIOConstants(com.emc.storageos.scaleio.api.ScaleIOConstants) ScaleIOSDSDataRestRep(com.emc.storageos.model.collectdata.ScaleIOSDSDataRestRep) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) ScaleIODeviceDataRestRep(com.emc.storageos.model.collectdata.ScaleIODeviceDataRestRep) ScaleIOSDC(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC) ScaleIOVolume(com.emc.storageos.scaleio.api.restapi.response.ScaleIOVolume) ScaleIODataMapper(com.emc.storageos.api.mapper.ScaleIODataMapper) Collectors(java.util.stream.Collectors) ScaleIORestClientFactory(com.emc.storageos.scaleio.api.restapi.ScaleIORestClientFactory) ScaleIODevice(com.emc.storageos.scaleio.api.restapi.response.ScaleIODevice) List(java.util.List) JSONException(org.codehaus.jettison.json.JSONException) DefaultPermissions(com.emc.storageos.security.authorization.DefaultPermissions) ScaleIOSDS(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDS) ScaleIOVolumeDataRestRep(com.emc.storageos.model.collectdata.ScaleIOVolumeDataRestRep) ScaleIOSystem(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSystem) ScaleIOStoragePool(com.emc.storageos.scaleio.api.restapi.response.ScaleIOStoragePool) ScaleIOException(com.emc.storageos.scaleio.ScaleIOException) ArrayList(java.util.ArrayList) ScaleIOVolumeDataRestRep(com.emc.storageos.model.collectdata.ScaleIOVolumeDataRestRep) ScaleIOSystemDataRestRep(com.emc.storageos.model.collectdata.ScaleIOSystemDataRestRep) ScaleIOSystem(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSystem) ScaleIOProtectionDomain(com.emc.storageos.scaleio.api.restapi.response.ScaleIOProtectionDomain) URI(java.net.URI) ScaleIODeviceDataRestRep(com.emc.storageos.model.collectdata.ScaleIODeviceDataRestRep) ScaleIOStoragePool(com.emc.storageos.scaleio.api.restapi.response.ScaleIOStoragePool) ScaleIOSDSDataRestRep(com.emc.storageos.model.collectdata.ScaleIOSDSDataRestRep) ScaleIOSDCDataRestRep(com.emc.storageos.model.collectdata.ScaleIOSDCDataRestRep) ScaleIODevice(com.emc.storageos.scaleio.api.restapi.response.ScaleIODevice) ScaleIOVolume(com.emc.storageos.scaleio.api.restapi.response.ScaleIOVolume) JSONException(org.codehaus.jettison.json.JSONException) ScaleIOSDS(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDS) ScaleIOException(com.emc.storageos.scaleio.ScaleIOException) ScaleIOFaultSet(com.emc.storageos.scaleio.api.restapi.response.ScaleIOFaultSet) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) ScaleIOSDC(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with ScaleIOSDC

use of com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC in project coprhd-controller by CoprHD.

the class ScaleIOCommunicationInterface method createHost.

/**
 * Create a Host object for every SDC that is found on the system. Create a single
 * initiator for the host in the specified Network.
 *
 * @param network [in] Network object to associated the hosts' initiator ports
 * @param queryAllSDCResult [in] - SDC query result
 */
private void createHost(Network network, List<ScaleIOSDC> allSDCs) {
    // Find the root tenant and associate any SDC hosts with it
    List<URI> tenantOrgList = _dbClient.queryByType(TenantOrg.class, true);
    Iterator<TenantOrg> it = _dbClient.queryIterativeObjects(TenantOrg.class, tenantOrgList);
    List<String> initiatorsToAddToNetwork = new ArrayList<>();
    URI rootTenant = null;
    while (it.hasNext()) {
        TenantOrg tenantOrg = it.next();
        if (TenantOrg.isRootTenant(tenantOrg)) {
            rootTenant = tenantOrg.getId();
            break;
        }
    }
    for (ScaleIOSDC sdc : allSDCs) {
        String ip = sdc.getSdcIp();
        String guid = sdc.getSdcGuid();
        // First we search by nativeGuid
        Host host = findByNativeGuid(guid);
        if (host == null) {
            // Host with nativeGuid is not known to ViPR, try and find by IP address
            host = findOrCreateByIp(rootTenant, ip, guid);
        }
        // Create an single initiator for this SDC. If the initiator has already been
        // created, the existing Initiator will be returned. Associate the initiator
        // with the network
        Initiator initiator = createInitiator(host, ip, sdc.getId());
        if (!network.hasEndpoint(initiator.getInitiatorPort())) {
            initiatorsToAddToNetwork.add(initiator.getInitiatorPort());
        }
    }
    if (!initiatorsToAddToNetwork.isEmpty()) {
        network.addEndpoints(initiatorsToAddToNetwork, true);
        _dbClient.updateAndReindexObject(network);
    }
}
Also used : ScaleIOScsiInitiator(com.emc.storageos.scaleio.api.restapi.response.ScaleIOScsiInitiator) ArrayList(java.util.ArrayList) URI(java.net.URI) ScaleIOSDC(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC)

Example 3 with ScaleIOSDC

use of com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC in project coprhd-controller by CoprHD.

the class ScaleIORestClientTest method testQuerySdc.

@Test
public void testQuerySdc() {
    try {
        List<ScaleIOSDC> result = restClient.queryAllSDC();
        System.out.println("ScaleIO SDC GUIDs");
        for (ScaleIOSDC sdc : result) {
            System.out.println(format("\tName: {0}, IP: {1}, State: {2}, GUID: {3}", sdc.getName(), sdc.getSdcIp(), sdc.getMdmConnectionState(), sdc.getSdcGuid()));
        }
    } catch (Exception e) {
        log.error("Exception: ", e);
        Assert.fail();
    }
}
Also used : ScaleIOSDC(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC) Test(org.junit.Test)

Example 4 with ScaleIOSDC

use of com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC in project coprhd-controller by CoprHD.

the class ScaleIOCommunicationInterface method discover.

@Override
public void discover(AccessProfile accessProfile) throws BaseCollectionException {
    StorageSystem.CompatibilityStatus compatibilityStatus = StorageSystem.CompatibilityStatus.COMPATIBLE;
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
    _locker.acquireLock(accessProfile.getIpAddress(), LOCK_WAIT_SECONDS);
    log.info("Starting discovery of ScaleIO StorageProvider. IP={} StorageSystem {}", accessProfile.getIpAddress(), storageSystem.getNativeGuid());
    String statusMsg = "";
    try {
        ScaleIORestClient scaleIOHandle = scaleIOHandleFactory.using(_dbClient).getClientHandle(storageSystem);
        if (scaleIOHandle != null) {
            ScaleIOSystem sioSystem = scaleIOHandle.getSystem();
            List<ScaleIOProtectionDomain> protectionDomains = scaleIOHandle.getProtectionDomains();
            List<ScaleIOSDC> allSDCs = scaleIOHandle.queryAllSDC();
            List<ScaleIOSDS> allSDSs = scaleIOHandle.queryAllSDS();
            List<ScaleIOScsiInitiator> allSCSIInitiators = scaleIOHandle.queryAllSCSIInitiators();
            List<StoragePort> ports = new ArrayList<>();
            List<StoragePool> newPools = new ArrayList<StoragePool>();
            List<StoragePool> updatePools = new ArrayList<StoragePool>();
            List<StoragePool> allPools = new ArrayList<StoragePool>();
            String scaleIOType = StorageSystem.Type.scaleio.name();
            String installationId = sioSystem.getInstallId();
            String version = sioSystem.getVersion().replaceAll("_", ".");
            String minimumSupported = VersionChecker.getMinimumSupportedVersion(StorageSystem.Type.scaleio);
            compatibilityStatus = (VersionChecker.verifyVersionDetails(minimumSupported, version) < 0) ? StorageSystem.CompatibilityStatus.INCOMPATIBLE : StorageSystem.CompatibilityStatus.COMPATIBLE;
            storageSystem.setFirmwareVersion(version);
            storageSystem.setCompatibilityStatus(compatibilityStatus.name());
            storageSystem.setReachableStatus(true);
            storageSystem.setLabel(storageSystem.getNativeGuid());
            for (ScaleIOProtectionDomain protectionDomain : protectionDomains) {
                String domainName = protectionDomain.getName();
                String id = String.format("%s+%s", installationId, domainName);
                String storageSystemNativeGUID = generateNativeGuid(scaleIOType, id);
                if (!storageSystemNativeGUID.equals(storageSystem.getNativeGuid())) {
                    // This is not the ProtectionDomain that we're looking for
                    continue;
                }
                String protectionDomainId = protectionDomain.getId();
                storageSystem.setSerialNumber(protectionDomainId);
                Network network = createNetwork(installationId);
                List<ScaleIOSDS> sdsList = new ArrayList<ScaleIOSDS>();
                for (ScaleIOSDS sds : allSDSs) {
                    String pdId = sds.getProtectionDomainId();
                    if (pdId.equals(protectionDomainId)) {
                        sdsList.add(sds);
                    }
                }
                List<StoragePort> thesePorts = createStoragePorts(storageSystem, compatibilityStatus.name(), network, sdsList, domainName);
                ports.addAll(thesePorts);
                createHost(network, allSDCs);
                boolean hasSCSIInitiators = createSCSIInitiatorsAndStoragePorts(storageSystem, domainName, compatibilityStatus, installationId, allSCSIInitiators, allSDCs, ports);
                List<StoragePort> notVisiblePorts = DiscoveryUtils.checkStoragePortsNotVisible(ports, _dbClient, storageSystem.getId());
                if (notVisiblePorts != null && !notVisiblePorts.isEmpty()) {
                    ports.addAll(notVisiblePorts);
                }
                Set<String> supportedProtocols = (hasSCSIInitiators) ? SCALEIO_AND_ISCSI : SCALEIO_ONLY;
                List<ScaleIOStoragePool> storagePools = scaleIOHandle.getProtectionDomainStoragePools(protectionDomainId);
                for (ScaleIOStoragePool storagePool : storagePools) {
                    String poolName = storagePool.getName();
                    String nativeGuid = String.format("%s-%s-%s", installationId, domainName, poolName);
                    log.info("Attempting to discover pool {} for ProtectionDomain {}", poolName, domainName);
                    List<StoragePool> pools = queryActiveResourcesByAltId(_dbClient, StoragePool.class, "nativeGuid", nativeGuid);
                    StoragePool pool = null;
                    if (pools.isEmpty()) {
                        log.info("Pool {} is new", poolName);
                        pool = new StoragePool();
                        pool.setId(URIUtil.createId(StoragePool.class));
                        pool.setStorageDevice(accessProfile.getSystemId());
                        pool.setPoolServiceType(StoragePool.PoolServiceType.block.toString());
                        pool.setOperationalStatus(StoragePool.PoolOperationalStatus.READY.name());
                        pool.setCompatibilityStatus(compatibilityStatus.name());
                        pool.setThinVolumePreAllocationSupported(false);
                        pool.addDriveTypes(Collections.singleton(StoragePool.SupportedDriveTypeValues.SATA.name()));
                        StringSet copyTypes = new StringSet();
                        copyTypes.add(StoragePool.CopyTypes.ASYNC.name());
                        copyTypes.add(StoragePool.CopyTypes.UNSYNC_UNASSOC.name());
                        pool.setSupportedCopyTypes(copyTypes);
                        pool.setMaximumThickVolumeSize(1048576L);
                        pool.setMinimumThickVolumeSize(1L);
                        newPools.add(pool);
                    } else if (pools.size() == 1) {
                        log.info("Pool {} was previously discovered", storagePool);
                        pool = pools.get(0);
                        updatePools.add(pool);
                    } else {
                        log.warn(String.format("There are %d StoragePools with nativeGuid = %s", pools.size(), nativeGuid));
                        continue;
                    }
                    pool.setPoolName(poolName);
                    pool.setNativeId(storagePool.getId());
                    pool.setNativeGuid(nativeGuid);
                    String availableCapacityString = storagePool.getCapacityAvailableForVolumeAllocationInKb();
                    pool.setFreeCapacity(Long.parseLong(availableCapacityString));
                    String totalCapacityString = storagePool.getMaxCapacityInKb();
                    pool.setTotalCapacity(Long.parseLong(totalCapacityString));
                    pool.addProtocols(supportedProtocols);
                    pool.setSupportedResourceTypes(StoragePool.SupportedResourceTypes.THIN_AND_THICK.name());
                    Long maxThinSize = 1048576L;
                    Long minThinSize = 1L;
                    pool.setMaximumThinVolumeSize(maxThinSize);
                    pool.setMinimumThinVolumeSize(minThinSize);
                    pool.setInactive(false);
                    pool.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
                }
            }
            log.info(String.format("For StorageSystem %s, discovered %d new pools and %d pools to update", storageSystem.getNativeGuid(), newPools.size(), updatePools.size()));
            StoragePoolAssociationHelper.setStoragePoolVarrays(storageSystem.getId(), newPools, _dbClient);
            allPools.addAll(newPools);
            allPools.addAll(updatePools);
            _dbClient.createObject(newPools);
            _dbClient.updateAndReindexObject(updatePools);
            List<StoragePool> notVisiblePools = DiscoveryUtils.checkStoragePoolsNotVisible(allPools, _dbClient, storageSystem.getId());
            if (notVisiblePools != null && !notVisiblePools.isEmpty()) {
                allPools.addAll(notVisiblePools);
            }
            StoragePortAssociationHelper.runUpdatePortAssociationsProcess(ports, null, _dbClient, _coordinator, allPools);
            statusMsg = String.format("Discovery completed successfully for Storage System: %s", storageSystem.getNativeGuid());
        }
    } catch (Exception e) {
        storageSystem.setReachableStatus(false);
        log.error(String.format("Exception was encountered when attempting to discover ScaleIO Instance %s", accessProfile.getIpAddress()), e);
        statusMsg = String.format("Discovery failed because %s", e.getLocalizedMessage());
        throw ScaleIOException.exceptions.discoveryFailed(e);
    } finally {
        _locker.releaseLock(accessProfile.getIpAddress());
        if (storageSystem != null) {
            storageSystem.setLastDiscoveryStatusMessage(statusMsg);
        }
    }
    _dbClient.updateAndReindexObject(storageSystem);
    log.info("Completed of ScaleIO StorageProvider. IP={} StorageSystem {}", accessProfile.getIpAddress(), storageSystem.getNativeGuid());
}
Also used : ScaleIOStoragePool(com.emc.storageos.scaleio.api.restapi.response.ScaleIOStoragePool) ArrayList(java.util.ArrayList) ScaleIOSystem(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSystem) ScaleIOProtectionDomain(com.emc.storageos.scaleio.api.restapi.response.ScaleIOProtectionDomain) ScaleIOStoragePool(com.emc.storageos.scaleio.api.restapi.response.ScaleIOStoragePool) ScaleIOSDS(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDS) IOException(java.io.IOException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ScaleIOException(com.emc.storageos.scaleio.ScaleIOException) ScaleIOScsiInitiator(com.emc.storageos.scaleio.api.restapi.response.ScaleIOScsiInitiator) ScaleIORestClient(com.emc.storageos.scaleio.api.restapi.ScaleIORestClient) ScaleIOSDC(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC)

Example 5 with ScaleIOSDC

use of com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC in project coprhd-controller by CoprHD.

the class ScaleIOCommunicationInterface method createSCSIStoragePorts.

/**
 * Create an iSCSI StoragePort for each SDC in the ScaleIO instance. The SDC would present iSCSI
 * targets to iSCSI initiators. These are psuedo-StoragePorts or the purpose of tying up
 * the host-end to the storage-end of the IP Network
 * <p/>
 * Note about StoragePorts created here: The iSCSI target ports are generated and created per StorageSystem, keeping them in line with
 * other arrays. However, ScaleIO itself has a different way of presenting the targets. The targets are actually on the SDC client hosts
 * -- any SDC client in the ScaleIO system that has the SCSI software running on it will be able to present an iSCSI target to an iSCSI
 * initiator. The name of this target will take the form of iqn.2010-12.com.ecs:[SDC GUID]. In order for ViPR to support multiple using
 * multiple StorageSystems (ProtectionDomains) using the same set of SDC, we have to invent targets per ProtectionDomain. This means
 * that we will created a slightly modified IDQ to distinguish between them: iqn.2010-12.com.ecs.[PD name]:[SDC GUID]. Having such an
 * implementation does not affect the volume export because ScaleIO does not require specifying the target.
 *
 * @param storageSystem [in] - StorageSystem object (ProtectionDomain)
 * @param compatibilityStatus [in] - Compatibility status to use on the ports
 * @param network [in] - Network to associate with the ports
 * @param queryAllSDCResult [in] - SDS query result
 */
private List<StoragePort> createSCSIStoragePorts(StorageSystem storageSystem, String protectionDomainName, DiscoveredDataObject.CompatibilityStatus compatibilityStatus, Network network, List<ScaleIOSDC> allSDCs) throws IOException {
    List<StoragePort> ports = new ArrayList<>();
    List<String> endpoints = new ArrayList<>();
    String fixedProtectionDomainName = protectionDomainName.replaceAll("\\s+", "").toLowerCase();
    for (ScaleIOSDC sdc : allSDCs) {
        String sdcGUID = sdc.getSdcGuid();
        String sdcIP = sdc.getSdcIp();
        String generatedTargetName = String.format("iqn.2010-12.com.ecs.%s:%s", fixedProtectionDomainName, sdcGUID.toLowerCase());
        StoragePort port;
        List<StoragePort> results = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, StoragePort.class, "portNetworkId", generatedTargetName);
        if (results == null || results.isEmpty()) {
            String nativeGUID = NativeGUIDGenerator.generateNativeGuid(storageSystem, sdcIP, NativeGUIDGenerator.ADAPTER);
            StorageHADomain adapter = new StorageHADomain();
            adapter.setStorageDeviceURI(storageSystem.getId());
            adapter.setId(URIUtil.createId(StorageHADomain.class));
            adapter.setAdapterName(sdcIP);
            adapter.setLabel(sdcIP);
            adapter.setNativeGuid(nativeGUID);
            adapter.setNumberofPorts("1");
            adapter.setAdapterType(StorageHADomain.HADomainType.FRONTEND.name());
            adapter.setInactive(false);
            _dbClient.createObject(adapter);
            port = new StoragePort();
            port.setId(URIUtil.createId(StoragePort.class));
            port.setPortNetworkId(generatedTargetName);
            port.setLabel(generatedTargetName);
            port.setStorageDevice(storageSystem.getId());
            port.setCompatibilityStatus(compatibilityStatus.name());
            port.setOperationalStatus(OperationalStatus.OK.name());
            port.setIpAddress(sdcIP);
            port.setNetwork(network.getId());
            port.setPortGroup("");
            port.setPortName(generatedTargetName);
            port.setPortType(StoragePort.PortType.frontend.name());
            port.setStorageHADomain(adapter.getId());
            port.setTransportType(StorageProtocol.Transport.IP.name());
            port.setInactive(false);
            port.setDiscoveryStatus(DiscoveryStatus.VISIBLE.name());
            _dbClient.createObject(port);
            endpoints.add(port.getPortNetworkId());
        } else {
            port = results.get(0);
        }
        ports.add(port);
    }
    network.addEndpoints(endpoints, true);
    _dbClient.updateAndReindexObject(network);
    return ports;
}
Also used : ArrayList(java.util.ArrayList) ScaleIOSDC(com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC)

Aggregations

ScaleIOSDC (com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDC)5 ArrayList (java.util.ArrayList)4 ScaleIOException (com.emc.storageos.scaleio.ScaleIOException)2 ScaleIORestClient (com.emc.storageos.scaleio.api.restapi.ScaleIORestClient)2 ScaleIOProtectionDomain (com.emc.storageos.scaleio.api.restapi.response.ScaleIOProtectionDomain)2 ScaleIOSDS (com.emc.storageos.scaleio.api.restapi.response.ScaleIOSDS)2 ScaleIOScsiInitiator (com.emc.storageos.scaleio.api.restapi.response.ScaleIOScsiInitiator)2 ScaleIOStoragePool (com.emc.storageos.scaleio.api.restapi.response.ScaleIOStoragePool)2 ScaleIOSystem (com.emc.storageos.scaleio.api.restapi.response.ScaleIOSystem)2 URI (java.net.URI)2 ScaleIODataMapper (com.emc.storageos.api.mapper.ScaleIODataMapper)1 ScaleIOCollectDataParam (com.emc.storageos.model.collectdata.ScaleIOCollectDataParam)1 ScaleIODeviceDataRestRep (com.emc.storageos.model.collectdata.ScaleIODeviceDataRestRep)1 ScaleIOSDCDataRestRep (com.emc.storageos.model.collectdata.ScaleIOSDCDataRestRep)1 ScaleIOSDSDataRestRep (com.emc.storageos.model.collectdata.ScaleIOSDSDataRestRep)1 ScaleIOSystemDataRestRep (com.emc.storageos.model.collectdata.ScaleIOSystemDataRestRep)1 ScaleIOVolumeDataRestRep (com.emc.storageos.model.collectdata.ScaleIOVolumeDataRestRep)1 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)1 ScaleIOConstants (com.emc.storageos.scaleio.api.ScaleIOConstants)1 ScaleIORestClientFactory (com.emc.storageos.scaleio.api.restapi.ScaleIORestClientFactory)1