Search in sources :

Example 1 with StorageProvider

use of com.emc.storageos.db.client.model.StorageProvider 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 2 with StorageProvider

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

the class StorageProviderService method getStorageProvider.

/**
 * @brief Show Storage provider
 *        This call allows user to fetch Storage Provider details such as provider
 *        host access credential details.
 *
 * @param id Storage Provider Identifier
 * @return Storage Provider details.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StorageProviderRestRep getStorageProvider(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, StorageProvider.class, "id");
    StorageProvider mgmtProvider = queryResource(id);
    return map(mgmtProvider);
}
Also used : MapStorageProvider(com.emc.storageos.api.mapper.functions.MapStorageProvider) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 3 with StorageProvider

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

the class StorageProviderService method getStorageProviderList.

/**
 * @brief List Storage providers
 *        This function allows user to fetch list of all Storage Providers information.
 *
 * @return List of Storage Providers.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StorageProviderList getStorageProviderList() {
    List<URI> ids = _dbClient.queryByType(StorageProvider.class, true);
    List<StorageProvider> mgmtProviders = _dbClient.queryObject(StorageProvider.class, ids);
    if (mgmtProviders == null) {
        throw APIException.badRequests.unableToFindStorageProvidersForIds(ids);
    }
    StorageProviderList providerList = new StorageProviderList();
    for (StorageProvider provider : mgmtProviders) {
        providerList.getStorageProviders().add(toNamedRelatedResource(provider));
    }
    return providerList;
}
Also used : StorageProviderList(com.emc.storageos.model.smis.StorageProviderList) MapStorageProvider(com.emc.storageos.api.mapper.functions.MapStorageProvider) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with StorageProvider

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

the class StorageProviderService method deleteStorageProvider.

/**
 * Delete Storage Provider
 *
 * @param id
 * @brief Delete a storage provider
 * @return
 */
@POST
@Path("/{id}/deactivate")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response deleteStorageProvider(@PathParam("id") URI id) {
    // Validate the provider
    ArgValidator.checkFieldUriType(id, StorageProvider.class, "id");
    StorageProvider provider = _dbClient.queryObject(StorageProvider.class, id);
    ArgValidator.checkEntityNotNull(provider, id, isIdEmbeddedInURL(id));
    // Verify the provider can be removed without leaving "dangling" storages.
    StringSet providerStorageSystems = provider.getStorageSystems();
    if (null != providerStorageSystems && !providerStorageSystems.isEmpty()) {
        // First we need to verify that all related storage systems has at least 2 providers
        for (String system : providerStorageSystems) {
            StorageSystem storageSys = _dbClient.queryObject(StorageSystem.class, URI.create(system));
            if (storageSys != null && !storageSys.getInactive() && storageSys.getProviders() != null && storageSys.getProviders().size() == 1) {
                throw APIException.badRequests.cannotDeleteProviderWithManagedStorageSystems(storageSys.getId());
            }
        }
        // Next we can clear this provider from storage systems.
        for (String system : providerStorageSystems) {
            StorageSystem storageSys = _dbClient.queryObject(StorageSystem.class, URI.create(system));
            provider.removeStorageSystem(_dbClient, storageSys);
        }
    }
    StringSet decommissionedSystems = provider.getDecommissionedSystems();
    if (null != decommissionedSystems && !decommissionedSystems.isEmpty()) {
        for (String decommissioned : decommissionedSystems) {
            DecommissionedResource oldRes = _dbClient.queryObject(DecommissionedResource.class, URI.create(decommissioned));
            if (oldRes != null) {
                _dbClient.markForDeletion(oldRes);
            }
        }
    }
    // Set to inactive.
    _dbClient.markForDeletion(provider);
    auditOp(OperationTypeEnum.DELETE_STORAGEPROVIDER, true, null, provider.getId().toString(), provider.getLabel(), provider.getIPAddress(), provider.getPortNumber(), provider.getUserName(), provider.getInterfaceType());
    return Response.ok().build();
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) DecommissionedResource(com.emc.storageos.db.client.model.DecommissionedResource) MapStorageProvider(com.emc.storageos.api.mapper.functions.MapStorageProvider) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) 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 5 with StorageProvider

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

the class StorageProviderService method updateStorageProvider.

/**
 * Update the Storage Provider. This is useful when we move arrays to some other
 * provider.
 *
 * @param id the URN of a ViPR Storage Provider
 * @brief Update Storage provider
 * @return Updated Storage Provider information.
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StorageProviderRestRep updateStorageProvider(@PathParam("id") URI id, StorageProviderUpdateParam param) {
    StorageProvider storageProvider = _dbClient.queryObject(StorageProvider.class, id);
    if (null == storageProvider || storageProvider.getInactive()) {
        throw APIException.notFound.unableToFindEntityInURL(id);
    } else {
        /*
             * Usecase is not to remove the provider instead we can update the old storage provider with
             * new provider details.
             */
        if (param.getName() != null && !param.getName().equals("") && !param.getName().equalsIgnoreCase(storageProvider.getLabel())) {
            checkForDuplicateName(param.getName(), StorageProvider.class);
            storageProvider.setLabel(param.getName());
        }
        // if the ip or port passed are different from the existing one
        // check to ensure a provider does not exist with the new ip + port combo
        String existingIPAddress = storageProvider.getIPAddress();
        Integer existingPortNumber = storageProvider.getPortNumber();
        if ((param.getIpAddress() != null && !param.getIpAddress().equals(existingIPAddress)) || (param.getPortNumber() != null && !param.getPortNumber().equals(existingPortNumber))) {
            String ipAddress = (param.getIpAddress() != null) ? param.getIpAddress() : existingIPAddress;
            Integer portNumber = (param.getPortNumber() != null) ? param.getPortNumber() : existingPortNumber;
            ArgValidator.checkFieldRange(portNumber, 1, 65535, "port_number");
            String providerKey = ipAddress + "-" + portNumber;
            List<StorageProvider> providers = CustomQueryUtility.getActiveStorageProvidersByProviderId(_dbClient, providerKey);
            if (providers != null && !providers.isEmpty()) {
                throw APIException.badRequests.invalidParameterStorageProviderAlreadyRegistered(providerKey);
            }
            // if and only if the connection with old IP is not alive.
            if (!existingIPAddress.equals(param.getIpAddress()) && isOldConnectionAlive(existingIPAddress, existingPortNumber, storageProvider.getInterfaceType()) && (storageProvider.getStorageSystems() != null && !storageProvider.getStorageSystems().isEmpty())) {
                throw APIException.badRequests.cannotUpdateProviderIP(existingIPAddress + "-" + existingPortNumber);
            }
            storageProvider.setIPAddress(ipAddress);
            storageProvider.setPortNumber(portNumber);
        }
        if (param.getUserName() != null && StringUtils.isNotBlank(param.getUserName())) {
            storageProvider.setUserName(param.getUserName());
        }
        if (param.getPassword() != null && StringUtils.isNotBlank(param.getPassword())) {
            storageProvider.setPassword(param.getPassword());
        }
        if (param.getUseSSL() != null) {
            storageProvider.setUseSSL(param.getUseSSL());
        }
        if (param.getInterfaceType() != null) {
            ArgValidator.checkFieldValueFromEnum(param.getInterfaceType(), "interface_type", EnumSet.of(StorageProvider.InterfaceType.hicommand, StorageProvider.InterfaceType.smis, StorageProvider.InterfaceType.ibmxiv, StorageProvider.InterfaceType.scaleioapi, StorageProvider.InterfaceType.xtremio, StorageProvider.InterfaceType.ddmc, StorageProvider.InterfaceType.unity));
            storageProvider.setInterfaceType(param.getInterfaceType());
        }
        if (param.getSecondaryUsername() != null) {
            ArgValidator.checkFieldNotEmpty(param.getSecondaryUsername(), "secondary_username");
            storageProvider.setSecondaryUsername(param.getSecondaryUsername());
        }
        if (param.getSecondaryPassword() != null) {
            ArgValidator.checkFieldNotEmpty(param.getSecondaryPassword(), "secondary_password");
            storageProvider.setSecondaryPassword(param.getSecondaryPassword());
        }
        if (param.getSecondaryURL() != null) {
            verifySecondaryParams(param.getSecondaryURL());
            storageProvider.setSecondaryURL(param.getSecondaryURL());
        }
        if (param.getElementManagerURL() != null) {
            storageProvider.setElementManagerURL(param.getElementManagerURL());
        }
        _dbClient.persistObject(storageProvider);
    }
    auditOp(OperationTypeEnum.UPDATE_STORAGEPROVIDER, true, null, storageProvider.getId().toString(), storageProvider.getLabel(), storageProvider.getIPAddress(), storageProvider.getPortNumber(), storageProvider.getUserName(), storageProvider.getInterfaceType());
    return map(storageProvider);
}
Also used : MapStorageProvider(com.emc.storageos.api.mapper.functions.MapStorageProvider) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

StorageProvider (com.emc.storageos.db.client.model.StorageProvider)97 URI (java.net.URI)44 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)26 ArrayList (java.util.ArrayList)24 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)23 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)19 Produces (javax.ws.rs.Produces)19 IOException (java.io.IOException)18 StringSet (com.emc.storageos.db.client.model.StringSet)17 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)15 Path (javax.ws.rs.Path)15 Consumes (javax.ws.rs.Consumes)11 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)10 MapStorageProvider (com.emc.storageos.api.mapper.functions.MapStorageProvider)8 StorageSystemViewObject (com.emc.storageos.plugins.StorageSystemViewObject)8 GET (javax.ws.rs.GET)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)7 BlockController (com.emc.storageos.volumecontroller.BlockController)7