Search in sources :

Example 36 with Initiator

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

the class HostService method createInitiator.

/**
 * Creates a new initiator for a host.
 *
 * @param id
 *            the URN of a ViPR Host
 * @param createParam
 *            the details of the initiator
 * @brief Create host initiator
 * @return the details of the host initiator when creation
 *         is successfully.
 * @throws DatabaseException
 *             when a database error occurs.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/initiators")
public TaskResourceRep createInitiator(@PathParam("id") URI id, InitiatorCreateParam createParam) throws DatabaseException {
    Host host = queryObject(Host.class, id, true);
    Cluster cluster = null;
    validateInitiatorData(createParam, null);
    // create and populate the initiator
    Initiator initiator = new Initiator();
    initiator.setHost(id);
    initiator.setHostName(host.getHostName());
    if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
        cluster = queryObject(Cluster.class, host.getCluster(), false);
        initiator.setClusterName(cluster.getLabel());
    }
    initiator.setId(URIUtil.createId(Initiator.class));
    populateInitiator(initiator, createParam);
    _dbClient.createObject(initiator);
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Initiator.class, initiator.getId(), taskId, ResourceOperationTypeEnum.ADD_HOST_INITIATOR);
    // if host in use. update export with new initiator
    if (ComputeSystemHelper.isHostInUse(_dbClient, host.getId())) {
        ComputeSystemController controller = getController(ComputeSystemController.class, null);
        controller.addInitiatorsToExport(initiator.getHost(), Arrays.asList(initiator.getId()), taskId);
    } else {
        // No updates were necessary, so we can close out the task.
        _dbClient.ready(Initiator.class, initiator.getId(), taskId);
    }
    auditOp(OperationTypeEnum.CREATE_HOST_INITIATOR, true, null, initiator.auditParameters());
    return toTask(initiator, taskId, op);
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 37 with Initiator

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

the class ActionableEventExecutor method removeInitiator.

/**
 * Method to remove an initiator from existing exports for a host.
 * NOTE: In order to maintain backwards compatibility, do not change the signature of this method.
 *
 * @param initiatorId the initiator to remove
 * @param eventId the event id
 * @return task for removing an initiator
 */
public TaskResourceRep removeInitiator(URI initiatorId, URI eventId) {
    Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorId);
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Initiator.class, initiator.getId(), taskId, ResourceOperationTypeEnum.DELETE_INITIATOR);
    if (ComputeSystemHelper.isInitiatorInUse(_dbClient, initiatorId.toString())) {
        computeController.removeInitiatorFromExport(eventId, initiator.getHost(), initiator.getId(), taskId);
    } else {
        _dbClient.ready(Initiator.class, initiator.getId(), taskId);
        _dbClient.markForDeletion(initiator);
    }
    return toTask(initiator, taskId, op);
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) Operation(com.emc.storageos.db.client.model.Operation)

Example 38 with Initiator

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

the class ExportGroupService method validatePathAdjustment.

/**
 * Validate the path adjustment request parameters
 *
 * @param exportGroup ExportGroup object
 * @param system StorageSystem object
 * @param param Export Path Adjustment Parameters
 * @param varray URI of the virtual array, used to check any supplied ports are in correct varray
 */
private void validatePathAdjustment(ExportGroup exportGroup, StorageSystem system, ExportPathsAdjustmentParam param, URI varray) {
    String systemType = system.getSystemType();
    if (!Type.vmax.name().equalsIgnoreCase(systemType) && !Type.vplex.name().equalsIgnoreCase(systemType)) {
        throw APIException.badRequests.exportPathAdjustmentSystemNotSupported(systemType);
    }
    List<ExportMask> exportMasks = ExportMaskUtils.getExportMasks(_dbClient, exportGroup, system.getId());
    if (exportMasks.isEmpty()) {
        throw APIException.badRequests.exportPathAdjustmentSystemExportGroupNotMatch(exportGroup.getLabel(), system.getNativeGuid());
    }
    ExportPathParameters pathParam = param.getExportPathParameters();
    if (pathParam == null) {
        throw APIException.badRequests.exportPathAdjustementNoPathParameters();
    }
    URI pgURI = pathParam.getPortGroup();
    // Check if exportMask has existing volumes, if it does, make sure no remove paths.
    for (ExportMask exportMask : exportMasks) {
        List<InitiatorPathParam> removePaths = param.getRemovedPaths();
        if (removePaths.isEmpty() || !exportMask.hasAnyExistingVolumes()) {
            continue;
        }
        Map<URI, List<URI>> removes = new HashMap<URI, List<URI>>();
        for (InitiatorPathParam initPath : removePaths) {
            removes.put(initPath.getInitiator(), initPath.getStoragePorts());
        }
        Map<URI, List<URI>> removedPathForMask = ExportMaskUtils.getRemovePathsForExportMask(exportMask, removes);
        if (removedPathForMask != null && !removedPathForMask.isEmpty() && pgURI == null) {
            _log.error("It has removed path for the ExportMask with existing volumes: " + exportMask.getMaskName());
            throw APIException.badRequests.externallyAddedVolumes(exportMask.getMaskName(), exportMask.getExistingVolumes().toString());
        }
    }
    // check adjusted paths are valid. initiators are in the export group, and the targets are in the storage system, and
    // in valid state.
    Map<URI, List<URI>> adjustedPaths = convertInitiatorPathParamToMap(param.getAdjustedPaths());
    List<URI> pathInitiatorURIs = new ArrayList<URI>(adjustedPaths.keySet());
    StringSet initiatorIds = exportGroup.getInitiators();
    if (!initiatorIds.containsAll(StringSetUtil.uriListToStringSet(pathInitiatorURIs))) {
        // Determine all the host URIs for the egInitiators
        Set<URI> egHostURIs = new HashSet<URI>();
        List<Initiator> egInitiators = ExportUtils.getExportGroupInitiators(exportGroup, _dbClient);
        for (Initiator egInitiator : egInitiators) {
            if (!NullColumnValueGetter.isNullURI(egInitiator.getHost())) {
                egHostURIs.add(egInitiator.getHost());
            }
        }
        // Now, only throw error if there are initiators that are not of any of the egHostURIs
        List<Initiator> pathInitiators = _dbClient.queryObject(Initiator.class, pathInitiatorURIs);
        List<String> badInitiators = new ArrayList<String>();
        for (Initiator pathInitiator : pathInitiators) {
            // Bad if not in the EG initiatorIds AND not from an identifiable host or not from a host in EG
            if (!initiatorIds.contains(pathInitiator.getId().toString())) {
                if (pathInitiator.getHost() == null || !egHostURIs.contains(pathInitiator.getHost())) {
                    badInitiators.add(pathInitiator.getHostName() + "-" + pathInitiator.getInitiatorPort());
                }
            }
        }
        if (!badInitiators.isEmpty()) {
            throw APIException.badRequests.exportPathAdjustmentAdjustedPathNotValid(Joiner.on(", ").join(badInitiators));
        }
    }
    Set<URI> pathTargets = new HashSet<URI>();
    for (List<URI> targets : adjustedPaths.values()) {
        pathTargets.addAll(targets);
    }
    Set<URI> systemPorts = new HashSet<URI>();
    URIQueryResultList storagePortURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(system.getId()), storagePortURIs);
    // Validate the targets to be provisioned have a valid state (COMPATIBLE, REGISTERED, and VISIBLE) and
    // that their tagged virtual array contains our varray.
    List<StoragePort> storagePorts = _dbClient.queryObject(StoragePort.class, storagePortURIs);
    for (StoragePort port : storagePorts) {
        if (!port.getInactive() && port.getCompatibilityStatus().equals(DiscoveredDataObject.CompatibilityStatus.COMPATIBLE.name()) && port.getRegistrationStatus().equals(StoragePort.RegistrationStatus.REGISTERED.name()) && port.getDiscoveryStatus().equals(DiscoveryStatus.VISIBLE.name()) && port.getTaggedVirtualArrays() != null && port.getTaggedVirtualArrays().contains(varray.toString())) {
            systemPorts.add(port.getId());
        }
    }
    if (!systemPorts.containsAll(pathTargets)) {
        // List only the invalid targets
        pathTargets.removeAll(systemPorts);
        throw APIException.badRequests.exportPathAdjustmentAdjustedPathNotValid(Joiner.on(",").join(pathTargets));
    }
}
Also used : HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) InitiatorPathParam(com.emc.storageos.model.block.export.InitiatorPathParam) ExportPathParameters(com.emc.storageos.model.block.export.ExportPathParameters) HashSet(java.util.HashSet)

Example 39 with Initiator

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

the class ExportGroupService method filterOutInitiatorsNotAssociatedWithVArray.

/**
 * Validate if the initiator is linked to the VirtualArray through some Network
 * Routine will examine the 'newInitiators' list and remove any that do not have any association
 * to the VirtualArrays associated with the StorageSystems.
 *
 * @param exportGroup [in] - ExportGroup object
 * @param storageSystems [in] - Collection of StorageSystem URIs associated with this VArray
 * @param connectedStorageSystems [in/out] - Optional parameter that will contain a list of
 *            StorageSystem URIs that have connections to the initiators
 * @param newInitiators [in/out] - List of initiator URIs to examine.
 */
private void filterOutInitiatorsNotAssociatedWithVArray(ExportGroup exportGroup, Collection<URI> storageSystems, List<URI> connectedStorageSystems, List<URI> newInitiators) {
    Iterator<URI> it = newInitiators.iterator();
    BlockStorageScheduler blockScheduler = new BlockStorageScheduler();
    blockScheduler.setDbClient(_dbClient);
    List<URI> exportGroupInitiatorURIs = StringSetUtil.stringSetToUriList(exportGroup.getInitiators());
    while (it.hasNext()) {
        URI uri = it.next();
        Initiator initiator = _dbClient.queryObject(Initiator.class, uri);
        if (initiator == null) {
            _log.info(String.format("Initiator %s was not found in DB. Will be eliminated from request payload.", uri.toString()));
            it.remove();
            continue;
        }
        Set<String> varraysConsidered = new HashSet<String>();
        if (!hasConnectivityToAllSystems(initiator, storageSystems, connectedStorageSystems, exportGroup) || !isInitiatorInStorageSystemsNetwork(exportGroup, initiator, storageSystems, varraysConsidered)) {
            _log.info(String.format("Initiator %s (%s) will be eliminated from the payload. " + "It was either not found to be connected to any of these StorageSystems [%s] that are " + "associated with VirtualArray(s) %s or not connected to any of its networks.", initiator.getInitiatorPort(), initiator.getId().toString(), Joiner.on(',').join(storageSystems), varraysConsidered.toString()));
            // connections to the StorageSystems.
            if (!exportGroupInitiatorURIs.contains(uri)) {
                it.remove();
            }
        }
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) BlockStorageScheduler(com.emc.storageos.volumecontroller.placement.BlockStorageScheduler) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) HashSet(java.util.HashSet)

Example 40 with Initiator

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

the class ExportGroupService method getHostConnectedInitiators.

/**
 * For a given set of storage arrays, find the registered initiators on a host that
 * can connect to all the storage arrays given the possible varrays.
 *
 * @param host the host
 * @param storageSystems the set of arrays
 * @exportGroup - ExportGroup used to determine the Varrays
 * @return the list of initiators that have connectivity to all the storage
 *         systems via the varray.
 */
private List<URI> getHostConnectedInitiators(Host host, Collection<URI> storageSystems, ExportGroup exportGroup) {
    List<URI> initiators = new ArrayList<URI>();
    List<Initiator> hostInitiators = getChildren(host.getId(), Initiator.class, "host");
    for (Initiator initiator : hostInitiators) {
        if (initiator.getRegistrationStatus().equals(RegistrationStatus.REGISTERED.toString()) && hasConnectivityToAllSystems(initiator, storageSystems, exportGroup)) {
            initiators.add(initiator.getId());
        }
    }
    return initiators;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Aggregations

Initiator (com.emc.storageos.db.client.model.Initiator)487 URI (java.net.URI)345 ArrayList (java.util.ArrayList)266 HashMap (java.util.HashMap)170 HashSet (java.util.HashSet)161 ExportMask (com.emc.storageos.db.client.model.ExportMask)156 List (java.util.List)119 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)102 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)98 Map (java.util.Map)85 StringSet (com.emc.storageos.db.client.model.StringSet)83 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)82 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)81 StoragePort (com.emc.storageos.db.client.model.StoragePort)78 NamedURI (com.emc.storageos.db.client.model.NamedURI)73 Set (java.util.Set)72 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)58 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)57 StringMap (com.emc.storageos.db.client.model.StringMap)55 Host (com.emc.storageos.db.client.model.Host)54