Search in sources :

Example 51 with URIQueryResultList

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

the class StoragePortService method checkForDuplicatePortNetworkIdWithinSystem.

/**
 * Check if a storage port with the same portNetworkId exists for the passed storage system.
 *
 * @param dbClient the db client
 * @param portNetworkId the port network id
 * @param systemURI the system uri
 */
public static void checkForDuplicatePortNetworkIdWithinSystem(DbClient dbClient, String portNetworkId, URI systemURI) {
    URIQueryResultList portUriList = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortEndpointConstraint(portNetworkId), portUriList);
    Iterator<URI> storagePortIter = portUriList.iterator();
    while (storagePortIter.hasNext()) {
        StoragePort port = dbClient.queryObject(StoragePort.class, storagePortIter.next());
        if (port != null && !port.getInactive() && port.getStorageDevice().toString().equals(systemURI.toString())) {
            throw APIException.badRequests.duplicateEntityWithField("StoragePort", "portNetworkId");
        }
    }
}
Also used : MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 52 with URIQueryResultList

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

the class StorageProviderService method addStorageSystem.

/**
 * Allows the user to add a storage system and rescans the provider.
 * After that corresponding provider should be able to be rescanned and add this system back to the list of managed systems.
 *
 * @param id id the URN of a ViPR Storage provider
 * @param param The storage system details.
 *
 * @brief Add a new storage system and rescan the provider.
 * @return An asynchronous task corresponding to the scan job scheduled for the provider.
 *
 * @throws BadRequestException When the system type is not valid or a
 *             storage system with the same native guid already exists.
 * @throws com.emc.storageos.db.exceptions.DatabaseException When an error occurs querying the database.
 * @throws ControllerException When an error occurs discovering the storage
 *             system.
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("/{id}/storage-systems")
public TaskResourceRep addStorageSystem(@PathParam("id") URI id, StorageSystemProviderRequestParam param) throws ControllerException {
    TaskResourceRep taskRep;
    URIQueryResultList list = new URIQueryResultList();
    ArgValidator.checkFieldNotEmpty(param.getSystemType(), "system_type");
    if (!StorageSystem.Type.isProviderStorageSystem(param.getSystemType())) {
        throw APIException.badRequests.cannotAddStorageSystemTypeToStorageProvider(param.getSystemType());
    }
    StorageProvider provider = _dbClient.queryObject(StorageProvider.class, id);
    ArgValidator.checkEntityNotNull(provider, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldNotEmpty(param.getSerialNumber(), "serialNumber");
    String nativeGuid = NativeGUIDGenerator.generateNativeGuid(param.getSystemType(), param.getSerialNumber());
    // check for duplicate StorageSystem.
    List<StorageSystem> systems = CustomQueryUtility.getActiveStorageSystemByNativeGuid(_dbClient, nativeGuid);
    if (systems != null && !systems.isEmpty()) {
        throw APIException.badRequests.invalidParameterProviderStorageSystemAlreadyExists("nativeGuid", nativeGuid);
    }
    int cleared = DecommissionedResource.removeDecommissionedFlag(_dbClient, nativeGuid, StorageSystem.class);
    if (cleared == 0) {
        log.info("Cleared {} decommissioned systems", cleared);
    } else {
        log.info("Did not find any decommissioned systems to clear. Continue to scan.");
    }
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    String taskId = UUID.randomUUID().toString();
    tasks.add(new AsyncTask(StorageProvider.class, provider.getId(), taskId));
    BlockController controller = getController(BlockController.class, provider.getInterfaceType());
    DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new ScanJobExec(controller));
    TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
    return taskList.getTaskList().listIterator().next();
}
Also used : BlockController(com.emc.storageos.volumecontroller.BlockController) TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) MapStorageProvider(com.emc.storageos.api.mapper.functions.MapStorageProvider) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 53 with URIQueryResultList

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

the class StorageSystemService method registerStorageSystem.

/**
 * Allows the user register the storage system with the passed id.
 *
 * @param id the URN of a ViPR storage system.
 *
 * @brief Register storage system
 * @return A StorageSystemRestRep reference specifying the data for the
 *         updated storage system.
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/register")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StorageSystemRestRep registerStorageSystem(@PathParam("id") URI id) throws ControllerException {
    // Validate the storage system.
    ArgValidator.checkFieldUriType(id, StorageSystem.class, "id");
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, id);
    ArgValidator.checkEntity(storageSystem, id, isIdEmbeddedInURL(id));
    // If not already registered, register it now.
    if (RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(storageSystem.getRegistrationStatus())) {
        storageSystem.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
        _dbClient.updateObject(storageSystem);
        startStorageSystem(storageSystem);
        auditOp(OperationTypeEnum.REGISTER_STORAGE_SYSTEM, true, null, storageSystem.getId().toString(), id.toString());
    }
    // Register all Pools.
    URIQueryResultList storagePoolURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePoolConstraint(id), storagePoolURIs);
    Iterator<URI> storagePoolIter = storagePoolURIs.iterator();
    List<StoragePool> registeredPools = new ArrayList<StoragePool>();
    while (storagePoolIter.hasNext()) {
        StoragePool pool = _dbClient.queryObject(StoragePool.class, storagePoolIter.next());
        if (pool.getInactive() || DiscoveredDataObject.RegistrationStatus.REGISTERED.toString().equals(pool.getRegistrationStatus())) {
            continue;
        }
        registerStoragePool(pool);
        registeredPools.add(pool);
    }
    // Register all Ports.
    URIQueryResultList storagePortURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(id), storagePortURIs);
    Iterator<URI> storagePortIter = storagePortURIs.iterator();
    while (storagePortIter.hasNext()) {
        StoragePort port = _dbClient.queryObject(StoragePort.class, storagePortIter.next());
        if (port.getInactive() || DiscoveredDataObject.RegistrationStatus.REGISTERED.toString().equals(port.getRegistrationStatus())) {
            continue;
        }
        registerStoragePort(port);
    }
    StringBuffer errorMessage = new StringBuffer();
    // Pool registration also update its varray relationship, so, we should also update vpool to pool relation.
    ImplicitPoolMatcher.matchModifiedStoragePoolsWithAllVirtualPool(registeredPools, _dbClient, _coordinator, errorMessage);
    return map(storageSystem);
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) ArrayList(java.util.ArrayList) MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 54 with URIQueryResultList

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

the class StorageSystemService method checkForDuplicatePortName.

/**
 * Check if a storage port with the same name exists for the passed storage system.
 *
 * @param name Port name
 * @param id Storage system id
 */
private void checkForDuplicatePortName(String name, URI systemURI) {
    URIQueryResultList storagePortURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(systemURI), storagePortURIs);
    Iterator<URI> storagePortIter = storagePortURIs.iterator();
    while (storagePortIter.hasNext()) {
        StoragePort port = _dbClient.queryObject(StoragePort.class, storagePortIter.next());
        if (port != null && !port.getInactive() && port.getLabel().equalsIgnoreCase(name)) {
            throw APIException.badRequests.duplicateLabel(name);
        }
    }
}
Also used : MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 55 with URIQueryResultList

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

the class StorageSystemService method deleteStoragePortGroup.

/**
 * Delete a storage port group
 *
 * @param id
 *            the URN of a ViPR storage port.
 *
 * @brief Delete a storage port group
 * @return The pending task
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-port-groups/{pgId}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteStoragePortGroup(@PathParam("id") URI id, @PathParam("pgId") URI pgId) {
    ArgValidator.checkFieldUriType(id, StorageSystem.class, "id");
    StorageSystem system = queryResource(id);
    // Only support for VMAX
    if (!DiscoveredDataObject.Type.vmax.name().equals(system.getSystemType())) {
        APIException.badRequests.operationNotSupportedForSystemType(OperationTypeEnum.CREATE_STORAGE_PORT_GROUP.name(), system.getSystemType());
    }
    ArgValidator.checkFieldUriType(pgId, StoragePortGroup.class, "portGroupId");
    StoragePortGroup portGroup = _dbClient.queryObject(StoragePortGroup.class, pgId);
    String task = UUID.randomUUID().toString();
    Operation op = null;
    if (portGroup == null || portGroup.getInactive()) {
        // The port group has been deleted
        op = _dbClient.createTaskOpStatus(StoragePortGroup.class, portGroup.getId(), task, ResourceOperationTypeEnum.DELETE_STORAGE_PORT_GROUP);
        op.ready();
    } else {
        // Check if the port group is used by any export mask
        URIQueryResultList queryResult = new URIQueryResultList();
        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMasksByPortGroup(portGroup.getId().toString()), queryResult);
        Iterator<URI> maskIt = queryResult.iterator();
        if (maskIt.hasNext()) {
            URI maskURI = maskIt.next();
            // The port group is used by at least one export mask, throw error
            ArgValidator.checkReference(StoragePortGroup.class, pgId, maskURI.toString());
        }
        op = _dbClient.createTaskOpStatus(StoragePortGroup.class, portGroup.getId(), task, ResourceOperationTypeEnum.DELETE_STORAGE_PORT_GROUP);
        _dbClient.updateObject(portGroup);
        BlockController controller = getController(BlockController.class, system.getSystemType());
        controller.deleteStoragePortGroup(system.getId(), portGroup.getId(), task);
    }
    auditOp(OperationTypeEnum.DELETE_STORAGE_PORT_GROUP, true, null, portGroup.getNativeGuid(), pgId.toString());
    recordStoragePoolPortEvent(OperationTypeEnum.DELETE_STORAGE_PORT_GROUP, OperationTypeEnum.DELETE_STORAGE_PORT_GROUP.getDescription(), portGroup.getId(), "StoragePortGroup");
    return toTask(portGroup, task, op);
}
Also used : MapStoragePortGroup(com.emc.storageos.api.mapper.functions.MapStoragePortGroup) StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) BlockController(com.emc.storageos.volumecontroller.BlockController) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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