Search in sources :

Example 96 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method removeInitiatorsUsingREST.

/**
 * Removes initiators from an existing export mask
 *
 * @param storage
 *            StorageSystem instance
 * @param exportMaskURI
 *            ExportMask URI where Initiator needs to be removed
 * @param volumeURIList
 *            Volume to be validated against this operation
 * @param initiatorList
 *            List of Initiators to be removed
 * @param taskCompleter
 *            Task Completer instance
 */
public void removeInitiatorsUsingREST(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    try {
        ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        XIVRestClient restExportOpr = getRestClient(storage);
        final String storageIP = storage.getSmisProviderIP();
        List<URI> userRemovedInitiators = new ArrayList<URI>();
        Set<URI> hostURIs = new HashSet<URI>();
        if (null != initiatorList) {
            for (Initiator initiator : initiatorList) {
                final Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                final String normalizedPort = Initiator.normalizePort(initiator.getInitiatorPort());
                if (restExportOpr.deleteHostPort(storageIP, host.getLabel(), normalizedPort, initiator.getProtocol().toLowerCase(), true)) {
                    userRemovedInitiators.add(initiator.getId());
                    hostURIs.add(initiator.getHost());
                }
            }
        }
        mask.removeFromUserAddedInitiatorsByURI(userRemovedInitiators);
        // Delete Host if there are no associated Initiators to it.
        for (URI hostURI : hostURIs) {
            Host host = _dbClient.queryObject(Host.class, hostURI);
            boolean hostDeleted = restExportOpr.deleteHost(storageIP, host.getLabel(), true);
            // Perform post-mask-delete cleanup steps
            if (hostDeleted) {
                unsetTag(host, storage.getSerialNumber());
            }
        }
        ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
        _dbClient.updateObject(mask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: addInitiator failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("addInitiator", e);
        taskCompleter.error(_dbClient, error);
    }
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) Initiator(com.emc.storageos.db.client.model.Initiator) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) HashSet(java.util.HashSet)

Example 97 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method addInitiatorsUsingREST.

/**
 * Add Initiators to an existing Export Mask.
 *
 * @param storage
 *            StorageSystem instance
 * @param exportMaskURI
 *            Export mask URI where the initiator needs to be added
 * @param volumeURIList
 *            Volume to be validated against this operation
 * @param initiatorList
 *            List of initiators need to be added
 * @param taskCompleter
 *            Task Completer instance
 */
public void addInitiatorsUsingREST(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    try {
        ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        XIVRestClient restExportOpr = getRestClient(storage);
        final String storageIP = storage.getSmisProviderIP();
        List<Initiator> userAddedInitiators = new ArrayList<Initiator>();
        for (Initiator initiator : initiatorList) {
            final Host host = _dbClient.queryObject(Host.class, initiator.getHost());
            // Add Initiators to Host.
            if (!restExportOpr.createHostPort(storageIP, host.getLabel(), Initiator.normalizePort(initiator.getInitiatorPort()), initiator.getProtocol().toLowerCase())) {
                userAddedInitiators.add(initiator);
            }
        }
        mask.addToUserCreatedInitiators(userAddedInitiators);
        ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
        _dbClient.updateObject(mask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: addInitiator failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("addInitiator", e);
        taskCompleter.error(_dbClient, error);
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) Host(com.emc.storageos.db.client.model.Host) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) XIVRestException(com.emc.storageos.xiv.api.XIVRestException)

Example 98 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method deleteRESTExportMask.

/**
 * Deletes the Export Mask and its attributes
 *
 * @param storage
 *            XIV storage system
 * @param exportMaskURI
 *            Export mask URI
 * @param volumeURIList
 *            Volume URI as list
 * @param targetURIList
 *            target port URI as list [ not used for xiv]
 * @param initiatorList
 *            Initiator port URI as list
 * @param taskCompleter
 *            task completer instance
 */
public void deleteRESTExportMask(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    try {
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        final String storageIP = storage.getSmisProviderIP();
        final String exportType = ExportMaskUtils.getExportType(_dbClient, exportMask);
        final String name = exportMask.getNativeId();
        final StringSet emInitiatorURIs = exportMask.getInitiators();
        final StringMap emVolumeURIs = exportMask.getVolumes();
        XIVRestClient restExportOpr = getRestClient(storage);
        Set<URI> hostURIs = new HashSet<URI>();
        // Un export Volumes
        if (null != emVolumeURIs) {
            Iterator<Entry<String, String>> emVolumeURIItr = emVolumeURIs.entrySet().iterator();
            while (emVolumeURIItr.hasNext()) {
                URI volUri = URI.create(emVolumeURIItr.next().getKey());
                if (URIUtil.isType(volUri, Volume.class)) {
                    Volume volume = _dbClient.queryObject(Volume.class, volUri);
                    restExportOpr.unExportVolume(storageIP, exportType, name, volume.getLabel());
                }
            }
        }
        // Delete initiators
        if (null != emInitiatorURIs) {
            for (String initiatorURI : emInitiatorURIs) {
                Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(initiatorURI));
                Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                hostURIs.add(host.getId());
                String normalizedPort = Initiator.normalizePort(initiator.getInitiatorPort());
                restExportOpr.deleteHostPort(storageIP, host.getLabel(), normalizedPort, initiator.getProtocol().toLowerCase(), false);
            }
        }
        // Delete Host if there are no associated Initiators/Volume to it.
        for (URI hostURI : hostURIs) {
            Host host = _dbClient.queryObject(Host.class, hostURI);
            boolean hostDeleted = restExportOpr.deleteHost(storageIP, host.getLabel(), false);
            // Perform post-mask-delete cleanup steps
            if (hostDeleted && emVolumeURIs.size() > 0) {
                unsetTag(host, storage.getSerialNumber());
            }
        }
        // Delete Cluster if there is no associated hosts to it.
        if (ExportGroup.ExportGroupType.Cluster.name().equals(exportType)) {
            restExportOpr.deleteCluster(storageIP, name);
        }
        ExportUtils.cleanupAssociatedMaskResources(_dbClient, exportMask);
        exportMask.setMaskName(NullColumnValueGetter.getNullURI().toString());
        exportMask.setLabel(NullColumnValueGetter.getNullURI().toString());
        exportMask.setNativeId(NullColumnValueGetter.getNullURI().toString());
        exportMask.setResource(NullColumnValueGetter.getNullURI().toString());
        _dbClient.updateObject(exportMask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: deleteExportMask failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("createExportMask", e);
        taskCompleter.error(_dbClient, error);
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) Entry(java.util.Map.Entry) Volume(com.emc.storageos.db.client.model.Volume) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) HashSet(java.util.HashSet)

Example 99 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class XtremIOExportOperations method addInitiatorToInitiatorGroup.

private void addInitiatorToInitiatorGroup(XtremIOClient client, String xioClusterName, String clusterName, String hostName, List<Initiator> initiatorsToBeCreated, Set<String> igNames, ExportMask exportMask, StorageSystem storage, TaskCompleter taskCompleter) throws Exception {
    XtremIOInitiatorGroup igGroup = null;
    // create initiator group folder and initiator group
    String igFolderName = getInitiatorGroupFolderName(clusterName, hostName, storage);
    if (null == client.getTagDetails(igFolderName, XTREMIO_ENTITY_TYPE.InitiatorGroup.name(), xioClusterName)) {
        _log.info("Creating IG Folder with name {}", igFolderName);
        client.createTag(igFolderName, null, XtremIOConstants.XTREMIO_ENTITY_TYPE.InitiatorGroup.name(), xioClusterName);
    }
    DataSource dataSource = dataSourceFactory.createXtremIOInitiatorGroupNameDataSource(hostName, storage);
    String igName = customConfigHandler.getComputedCustomConfigValue(CustomConfigConstants.XTREMIO_INITIATOR_GROUP_NAME, storage.getSystemType(), dataSource);
    igGroup = client.getInitiatorGroup(igName, xioClusterName);
    if (null == igGroup) {
        // create a new IG
        _log.info("Creating Initiator Group with name {}", igName);
        client.createInitiatorGroup(igName, igFolderName, xioClusterName);
        ExportOperationContext.insertContextOperation(taskCompleter, XtremIOExportOperationContext.OPERATION_CREATE_INITIATOR_GROUP, igName);
        igGroup = client.getInitiatorGroup(igName, xioClusterName);
        if (null == igGroup) {
            _log.info("Neither IG is already present nor able to create on Array {}", hostName);
        } else {
            _log.info("Created Initiator Group {} with # initiators {}", igGroup.getName(), igGroup.getNumberOfInitiators());
            igNames.add(igGroup.getName());
        }
    } else {
        igNames.add(igGroup.getName());
        _log.info("Found Initiator Group {} with # initiators {}", igGroup.getName(), igGroup.getNumberOfInitiators());
    }
    // add all the left out initiators to this folder
    for (Initiator remainingInitiator : initiatorsToBeCreated) {
        _log.info("Initiator {} Label {} ", remainingInitiator.getInitiatorPort(), remainingInitiator.getLabel());
        String initiatorName = ((null == remainingInitiator.getLabel() || remainingInitiator.getLabel().isEmpty()) ? remainingInitiator.getInitiatorPort() : remainingInitiator.getLabel());
        List<Initiator> createdInitiators = new ArrayList<Initiator>();
        _log.info("Initiator {}  ", initiatorName);
        try {
            String os = null;
            if (client.isVersion2() && !NullColumnValueGetter.isNullURI(remainingInitiator.getHost())) {
                Host host = dbClient.queryObject(Host.class, remainingInitiator.getHost());
                os = XtremIOProvUtils.getInitiatorHostOS(host);
            }
            // create initiator
            client.createInitiator(initiatorName, igGroup.getName(), remainingInitiator.getInitiatorPort(), os, xioClusterName);
            createdInitiators.add(remainingInitiator);
            remainingInitiator.setLabel(initiatorName);
            remainingInitiator.mapInitiatorName(storage.getSerialNumber(), initiatorName);
            dbClient.updateObject(remainingInitiator);
        } catch (Exception e) {
            // assume initiator already part of another group look for
            // port_address_not_unique
            // CTRL-5956 - Few Initiators cannot be registered on XtremIO Array, throw exception even if one
            // initiator registration
            // fails.
            _log.warn("Initiator {} already available or not able to register the same on Array. Rediscover the Array and try again.", remainingInitiator.getInitiatorPort());
            throw e;
        } finally {
            ExportOperationContext.insertContextOperation(taskCompleter, XtremIOExportOperationContext.OPERATION_ADD_INITIATORS_TO_INITIATOR_GROUP, createdInitiators);
        }
    }
}
Also used : XtremIOInitiatorGroup(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiatorGroup) XtremIOInitiator(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataSource(com.emc.storageos.customconfigcontroller.DataSource)

Example 100 with Host

use of com.emc.storageos.db.client.model.Host in project coprhd-controller by CoprHD.

the class StaleRelationURICleanupMigrationTest method testForExportGroup.

@Test
public void testForExportGroup() throws Exception {
    List<Initiator> existingInitiators = createActiveDataObject(Initiator.class, 2);
    List<Host> existingHosts = createActiveDataObject(Host.class, 2);
    ExportMask exportMask = createActiveDataObject(ExportMask.class, 1).get(0);
    ExportGroup exportGroup = new ExportGroup();
    exportGroup.setId(URIUtil.createId(ExportGroup.class));
    exportGroup.setLabel("label");
    exportGroup.setInactive(false);
    exportGroup.addInitiators(retrieveIDURIs(createFakeDataObject(Initiator.class, 5)));
    exportGroup.addInitiators(retrieveIDURIs(createInactiveDataObject(Initiator.class, 5)));
    exportGroup.addInitiators(retrieveIDURIs(existingInitiators));
    exportGroup.addHosts(retrieveIDURIs(createFakeDataObject(Host.class, 1)));
    exportGroup.addHosts(retrieveIDURIs(createInactiveDataObject(Host.class, 1)));
    exportGroup.addHosts(retrieveIDURIs(existingHosts));
    exportGroup.addVolumes(createFakeDataObjectMap(Volume.class, 5));
    exportGroup.addVolumes(createInactiveDataObjectMap(Volume.class, 5));
    exportGroup.setSnapshots(new StringSet());
    exportGroup.getSnapshots().add(URIUtil.createId(BlockSnapshot.class).toString());
    exportGroup.addClusters(retrieveIDURIs(createFakeDataObject(Cluster.class, 5)));
    exportGroup.addClusters(retrieveIDURIs(createInactiveDataObject(Cluster.class, 5)));
    exportGroup.addExportMask(exportMask.getId());
    _dbClient.updateObject(exportGroup);
    ExportGroup target = _dbClient.queryObject(ExportGroup.class, exportGroup.getId());
    Assert.assertTrue(SetUtils.isEqualSet(exportGroup.getInitiators(), target.getInitiators()));
    Assert.assertTrue(SetUtils.isEqualSet(exportGroup.getHosts(), target.getHosts()));
    Assert.assertTrue(Maps.difference(exportGroup.getVolumes(), target.getVolumes()).areEqual());
    Assert.assertTrue(SetUtils.isEqualSet(exportGroup.getSnapshots(), target.getSnapshots()));
    Assert.assertTrue(SetUtils.isEqualSet(exportGroup.getClusters(), target.getClusters()));
    Assert.assertTrue(SetUtils.isEqualSet(exportGroup.getExportMasks(), target.getExportMasks()));
    callback.process();
    target = _dbClient.queryObject(ExportGroup.class, exportGroup.getId());
    Assert.assertEquals(existingInitiators.size(), target.getInitiators().size());
    for (Initiator initiator : existingInitiators) {
        Assert.assertTrue(target.getInitiators().contains(initiator.getId().toString()));
    }
    Assert.assertEquals(existingHosts.size(), target.getHosts().size());
    for (Host host : existingHosts) {
        Assert.assertTrue(target.getHosts().contains(host.getId().toString()));
    }
    Assert.assertTrue(target.getSnapshots() == null || target.getSnapshots().isEmpty());
    Assert.assertTrue(target.getClusters() == null || target.getClusters().isEmpty());
    Assert.assertEquals(1, target.getExportMasks().size());
    Assert.assertEquals(exportMask.getId().toString(), target.getExportMasks().toArray()[0]);
    Assert.assertTrue(target.getVolumes() == null || target.getVolumes().isEmpty());
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) Volume(com.emc.storageos.db.client.model.Volume) ExportMask(com.emc.storageos.db.client.model.ExportMask) StringSet(com.emc.storageos.db.client.model.StringSet) Host(com.emc.storageos.db.client.model.Host) Test(org.junit.Test)

Aggregations

Host (com.emc.storageos.db.client.model.Host)227 URI (java.net.URI)104 Initiator (com.emc.storageos.db.client.model.Initiator)52 ArrayList (java.util.ArrayList)49 HashMap (java.util.HashMap)38 Cluster (com.emc.storageos.db.client.model.Cluster)37 HashSet (java.util.HashSet)35 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)33 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)32 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)26 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)24 Volume (com.emc.storageos.db.client.model.Volume)20 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 Vcenter (com.emc.storageos.db.client.model.Vcenter)19 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)18 ExportMask (com.emc.storageos.db.client.model.ExportMask)18 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)17 NamedURI (com.emc.storageos.db.client.model.NamedURI)16 StringSet (com.emc.storageos.db.client.model.StringSet)16