Search in sources :

Example 31 with Initiator

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

the class NetworkZoningParam method updateZoningParamUsingFCZoneReference.

/**
 * Build the zoningMap attribute of zoningParam using FCZoneReference and exportGroup
 *
 * @param zoningParam
 * @param initsToRemoveOnlyFromZone
 * @param exportGroup
 */
public static void updateZoningParamUsingFCZoneReference(List<NetworkZoningParam> zoningParam, List<URI> initsToRemoveOnlyFromZone, ExportGroup exportGroup, DbClient dbClient) {
    HashMap<String, Initiator> initiatorMap = new HashMap<String, Initiator>();
    for (URI initiatorURI : initsToRemoveOnlyFromZone) {
        Initiator iniObject = dbClient.queryObject(Initiator.class, initiatorURI);
        String iniString = iniObject.getInitiatorPort().toUpperCase();
        initiatorMap.put(iniString, iniObject);
    }
    // Retrieve FCZoneReference zone references that have the same initiator WWN.
    // These zone should be removed. since the initiator is no longer available.
    List<FCZoneReference> fcRefs = NetworkUtil.getFCZoneReferencesFromExportGroup(dbClient, exportGroup);
    Set<String> iniConsidered = new HashSet<String>();
    for (NetworkZoningParam networkZoningParam : zoningParam) {
        StringSetMap zoneMap = networkZoningParam.getZoningMap();
        if (zoneMap.isEmpty()) {
            for (FCZoneReference fcZoneReference : fcRefs) {
                String[] initiatorAndPort = getInitiatorAndPortFromPwwnKey(fcZoneReference.getPwwnKey());
                if (initiatorAndPort != null) {
                    String initiator = initiatorAndPort[0];
                    String port = initiatorAndPort[1];
                    Initiator iniObject = initiatorMap.get(initiator);
                    if (iniObject != null) {
                        StoragePort sp = NetworkUtil.getStoragePort(port, dbClient);
                        if (sp != null) {
                            iniConsidered.add(iniObject.getInitiatorPort());
                            zoneMap.put(iniObject.getId().toString(), sp.getId().toString());
                        }
                    }
                } else {
                    _log.warn("Could not obtain initiator and port correctly from the PwwnKey {}", fcZoneReference.getPwwnKey());
                }
            }
            // removed the initiator from map the as this initiator is considered for zone map
            if (!iniConsidered.isEmpty()) {
                initiatorMap.keySet().removeAll(iniConsidered);
            }
        }
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) Initiator(com.emc.storageos.db.client.model.Initiator) HashSet(java.util.HashSet)

Example 32 with Initiator

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

the class InitiatorService method setInitiatorAlias.

/**
 * Sets the alias/initiator name for an initiator
 * on the Storage System
 *
 * @param id the URN of a ViPR initiator
 * @param aliasSetParam the parameter containing the storage system and alias attributes
 * @prereq none
 * @brief Set the serial number and alias on this storage system for an initiator
 * @return A reference to an InitiatorRestRep representing the Initiator Alias after Set..
 * @throws Exception When an error occurs setting the alias on a VMAX Storage System.
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/alias")
public InitiatorAliasRestRep setInitiatorAlias(@PathParam("id") URI id, InitiatorAliasSetParam aliasSetParam) {
    // Basic Checks
    Initiator initiator = queryResource(id);
    verifyUserPermisions(initiator);
    URI systemURI = aliasSetParam.getSystemURI();
    ArgValidator.checkFieldUriType(systemURI, StorageSystem.class, "id");
    StorageSystem system = _permissionsHelper.getObjectById(systemURI, StorageSystem.class);
    ArgValidator.checkEntity(system, systemURI, isIdEmbeddedInURL(systemURI));
    String initiatorAlias = aliasSetParam.getInitiatorAlias();
    ArgValidator.checkFieldNotNull(initiatorAlias, "alias");
    if (!initiatorAlias.contains(EMPTY_INITIATOR_ALIAS)) {
        ArgValidator.checkFieldLengthMaximum(initiatorAlias, ALIAS_MAX_LIMIT, "alias");
    } else {
        ArgValidator.checkFieldLengthMaximum(initiatorAlias.split(EMPTY_INITIATOR_ALIAS)[0], ALIAS_MAX_LIMIT, "alias node name");
        ArgValidator.checkFieldLengthMaximum(initiatorAlias.split(EMPTY_INITIATOR_ALIAS)[1], ALIAS_MAX_LIMIT, "alias port name");
    }
    if (initiatorAlias.matches(ALIAS_ILLEGAL_CHARACTERS)) {
        String errMsg = String.format("Supplied Alias: %s has invalid characters", initiatorAlias);
        _log.error(errMsg);
        throw DeviceControllerException.exceptions.couldNotPerformAliasOperation(errMsg);
    }
    _log.info("Setting alias- {} for initiator {} on system {}", initiatorAlias, id, systemURI);
    if (system != null && StorageSystem.Type.vmax.toString().equalsIgnoreCase(system.getSystemType())) {
        BlockController controller = getController(BlockController.class, system.getSystemType());
        try {
            // Actual Control
            controller.setInitiatorAlias(systemURI, id, initiatorAlias);
        } catch (Exception e) {
            _log.error("Unexpected error: Setting alias failed.", e);
            throw APIException.badRequests.unableToProcessRequest(e.getMessage());
        }
    } else {
        throw APIException.badRequests.operationNotSupportedForSystemType(ALIAS, system.getSystemType());
    }
    // Update the Initiator here..
    if (initiatorAlias.contains(EMPTY_INITIATOR_ALIAS)) {
        // If the Initiator Alias contains the "/" character, the user has supplied
        // different node and port names.
        initiator.mapInitiatorName(system.getSerialNumber(), initiatorAlias);
    } else {
        // The user has set the same node and port names.
        initiatorAlias = String.format("%s%s%s", initiatorAlias, EMPTY_INITIATOR_ALIAS, initiatorAlias);
        initiator.mapInitiatorName(system.getSerialNumber(), initiatorAlias);
    }
    _dbClient.updateObject(initiator);
    return new InitiatorAliasRestRep(system.getSerialNumber(), initiatorAlias);
}
Also used : MapInitiator(com.emc.storageos.api.mapper.functions.MapInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) BlockController(com.emc.storageos.volumecontroller.BlockController) InitiatorAliasRestRep(com.emc.storageos.model.host.InitiatorAliasRestRep) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 33 with Initiator

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

the class InitiatorService method registerInitiator.

/**
 * Manually register the initiator with the passed id.
 *
 * @param id the URN of a ViPR initiator
 *
 * @brief Register initiator
 * @return A reference to an InitiatorRestRep specifying the data for the
 *         initiator.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/register")
public InitiatorRestRep registerInitiator(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Initiator.class, "id");
    Initiator initiator = _dbClient.queryObject(Initiator.class, id);
    ArgValidator.checkEntity(initiator, id, isIdEmbeddedInURL(id));
    if (RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(initiator.getRegistrationStatus())) {
        initiator.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
        _dbClient.persistObject(initiator);
        auditOp(OperationTypeEnum.REGISTER_INITIATOR, true, null, initiator.getId().toString());
    }
    return map(initiator);
}
Also used : MapInitiator(com.emc.storageos.api.mapper.functions.MapInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) 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 34 with Initiator

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

the class InitiatorService method updateInitiator.

/**
 * Update a host initiator.
 *
 * @param id the URN of a ViPR initiator
 * @param updateParam the parameter containing the new attributes
 * @prereq none
 * @brief Update initiator.
 * @return the details of the updated host initiator.
 * @throws DatabaseException when a DB error occurs
 */
@PUT
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public InitiatorRestRep updateInitiator(@PathParam("id") URI id, InitiatorUpdateParam updateParam) throws DatabaseException {
    Initiator initiator = queryObject(Initiator.class, id, true);
    _hostService.validateInitiatorData(updateParam, initiator);
    _hostService.populateInitiator(initiator, updateParam);
    _dbClient.persistObject(initiator);
    auditOp(OperationTypeEnum.UPDATE_HOST_INITIATOR, true, null, initiator.auditParameters());
    return map(queryObject(Initiator.class, id, false));
}
Also used : MapInitiator(com.emc.storageos.api.mapper.functions.MapInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 35 with Initiator

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

the class InitiatorService method deregisterInitiator.

/**
 * Allows the user to deregister a registered initiator so that it is no
 * longer used by the system. This simply sets the registration_status of
 * the initiator to UNREGISTERED.
 *
 * @param id the URN of a ViPR initiator
 *
 * @brief Unregister initiator
 * @return Status response indicating success or failure
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.TENANT_ADMIN })
public InitiatorRestRep deregisterInitiator(@PathParam("id") URI id) {
    Initiator initiator = queryResource(id);
    ArgValidator.checkEntity(initiator, id, isIdEmbeddedInURL(id));
    if (ComputeSystemHelper.isInitiatorInUse(_dbClient, id.toString())) {
        throw APIException.badRequests.resourceHasActiveReferencesWithType(Initiator.class.getSimpleName(), initiator.getId(), ExportGroup.class.getSimpleName());
    }
    if (RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(initiator.getRegistrationStatus())) {
        initiator.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
        _dbClient.persistObject(initiator);
        auditOp(OperationTypeEnum.DEREGISTER_INITIATOR, true, null, initiator.getLabel(), initiator.getId().toString());
    }
    return map(initiator);
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) MapInitiator(com.emc.storageos.api.mapper.functions.MapInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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