Search in sources :

Example 6 with StorageProvider

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

the class SMISProviderService method getStorageSystems.

/**
 * Allows the user to get the id, name, and self link for all storage
 * systems visible to the provider with the passed id.
 * <p>
 * The method is deprecated. Use /vdc/storage-providers/{id}/storage-systems
 *
 * @param id the URN of a ViPR SMI-S provider
 *
 * @brief List SMI-S provider storage systems
 * @return A StorageSystemList reference specifying the id, name, and self
 *         link for the storage systems visible to the provider.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-systems")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StorageSystemList getStorageSystems(@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));
    // Return the list of storage systems for the provider.
    StorageSystemList storageSystemsForProvider = new StorageSystemList();
    StringSet providerSystemURIStrs = provider.getStorageSystems();
    if (providerSystemURIStrs != null) {
        for (String providerSystemURIStr : providerSystemURIStrs) {
            StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, URI.create(providerSystemURIStr));
            if (storageSystem != null) {
                storageSystemsForProvider.getStorageSystems().add(toNamedRelatedResource(storageSystem));
            }
        }
    }
    return storageSystemsForProvider;
}
Also used : StorageSystemList(com.emc.storageos.model.systems.StorageSystemList) StringSet(com.emc.storageos.db.client.model.StringSet) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with StorageProvider

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

the class SMISProviderService method deleteSMISProvider.

/**
 * Allows the user to deactivate an SMI-S provider.
 * <p>
 * The method is deprecated. Use /vdc/storage-providers/{id}/deactivate instead.
 *
 * @param id the URN of a ViPR SMI-S provider
 *
 * @brief Delete SMI-S provider
 * @return Status indicating success or failure.
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
public Response deleteSMISProvider(@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.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_SMISPROVIDER, true, null, provider.getId().toString(), provider.getLabel(), provider.getIPAddress(), provider.getPortNumber(), provider.getUserName());
    return Response.ok().build();
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) DecommissionedResource(com.emc.storageos.db.client.model.DecommissionedResource) 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) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with StorageProvider

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

the class SMISProviderService method registerSMISProvider.

/**
 * Register an SMI-S provider to create storage systems of type
 * vnxblock and vmax. This call is not used to create SMI-S
 * providers for vnxfile.
 * <p>
 * The method is deprecated. Use /vdc/storage-providers instead.
 *
 * @param param SMIS-Provider parameters
 * @brief Register SMI-S provider
 * @return Newly registered SMIS-Provider details
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
public TaskResourceRep registerSMISProvider(SMISProviderCreateParam param) throws ControllerException {
    String providerKey = param.getIpAddress() + "-" + param.getPortNumber();
    List<StorageProvider> providers = CustomQueryUtility.getActiveStorageProvidersByProviderId(_dbClient, providerKey);
    if (providers != null && !providers.isEmpty()) {
        throw APIException.badRequests.invalidParameterSMISProviderAlreadyRegistered(providerKey);
    }
    ArgValidator.checkFieldNotEmpty(param.getName(), "name");
    checkForDuplicateName(param.getName(), StorageProvider.class);
    ArgValidator.checkFieldNotEmpty(param.getIpAddress(), "ip_address");
    ArgValidator.checkFieldNotNull(param.getPortNumber(), "port_number");
    ArgValidator.checkFieldNotEmpty(param.getUserName(), "user_name");
    ArgValidator.checkFieldNotEmpty(param.getPassword(), "password");
    ArgValidator.checkFieldNotNull(param.getUseSSL(), "use_ssl");
    ArgValidator.checkFieldRange(param.getPortNumber(), 1, 65535, "port_number");
    StorageProvider smisProvider = new StorageProvider();
    smisProvider.setInterfaceType(StorageProvider.InterfaceType.smis.name());
    smisProvider.setId(URIUtil.createId(StorageProvider.class));
    smisProvider.setLabel(param.getName());
    smisProvider.setIPAddress(param.getIpAddress());
    smisProvider.setPortNumber(param.getPortNumber());
    smisProvider.setUserName(param.getUserName());
    smisProvider.setPassword(param.getPassword());
    smisProvider.setUseSSL(param.getUseSSL());
    smisProvider.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
    _dbClient.createObject(smisProvider);
    auditOp(OperationTypeEnum.REGISTER_SMISPROVIDER, true, null, smisProvider.getLabel(), smisProvider.getId().toString(), smisProvider.getIPAddress(), smisProvider.getPortNumber(), smisProvider.getUserName());
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    String taskId = UUID.randomUUID().toString();
    tasks.add(new AsyncTask(StorageProvider.class, smisProvider.getId(), taskId));
    // @TODO revisit this to avoid hard coding.
    BlockController controller = getController(BlockController.class, "vnxblock");
    /**
     * Creates MonitoringJob token for vnxblock/vmax device on zooKeeper queue
     */
    controller.startMonitoring(new AsyncTask(StorageProvider.class, smisProvider.getId(), taskId), StorageSystem.Type.vnxblock);
    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) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 9 with StorageProvider

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

the class SMISProviderService method updateSMISProvider.

/**
 * Update the SMISProvider. This is useful when we move arrays to some other
 * provider.
 * <p>
 * The method is deprecated. Use /vdc/storage-providers/{id} instead.
 *
 * @param id the URN of a ViPR SMIS-Provider
 * @brief Update SMI-S provider
 * @return Updated SMIS-Provider information.
 */
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
public SMISProviderRestRep updateSMISProvider(@PathParam("id") URI id, SMISProviderUpdateParam param) {
    StorageProvider smisProvider = _dbClient.queryObject(StorageProvider.class, id);
    if (null == smisProvider) {
        throw APIException.notFound.unableToFindEntityInURL(id);
    } else if (!smisProvider.getInactive()) {
        /*
             * Usecase is not to remove the provider instead we can update the old smisprovider with
             * new provider details.
             */
        if (param.getName() != null && !param.getName().equals("") && !param.getName().equalsIgnoreCase(smisProvider.getLabel())) {
            checkForDuplicateName(param.getName(), StorageProvider.class);
            smisProvider.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 = smisProvider.getIPAddress();
        Integer existingPortNumber = smisProvider.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.invalidParameterSMISProviderAlreadyRegistered(providerKey);
            }
            // if and only if the connection with old IP is not alive.
            if (!existingIPAddress.equals(param.getIpAddress()) && isOldConnectionAlive(existingIPAddress, existingPortNumber, smisProvider.getInterfaceType())) {
                throw APIException.badRequests.cannotUpdateProviderIP(existingIPAddress + "-" + existingPortNumber);
            }
            smisProvider.setIPAddress(ipAddress);
            smisProvider.setPortNumber(portNumber);
        }
        if (param.getUserName() != null && !param.getUserName().equals("")) {
            smisProvider.setUserName(param.getUserName());
        }
        if (param.getPassword() != null && !param.getPassword().equals("")) {
            smisProvider.setPassword(param.getPassword());
        }
        if (param.getUseSSL() != null) {
            smisProvider.setUseSSL(param.getUseSSL());
        }
        _dbClient.persistObject(smisProvider);
    }
    auditOp(OperationTypeEnum.UPDATE_SMISPROVIDER, true, null, smisProvider.getId().toString(), smisProvider.getLabel(), smisProvider.getIPAddress(), smisProvider.getPortNumber(), smisProvider.getUserName());
    return mapStorageProviderToSMISRep(smisProvider);
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SMISProviderList(com.emc.storageos.model.smis.SMISProviderList) StorageSystemList(com.emc.storageos.model.systems.StorageSystemList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) 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)

Example 10 with StorageProvider

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

the class SMISProviderService method getStorageSystem.

/**
 * Allows the user to get data for the storage system with the passed system
 * id that is associated with the SMI-S provider with the passed provider
 * id.
 * <p>
 * The method is deprecated. Use /vdc/storage-providers/{id}/storage-systems/{systemId}
 *
 * @param id the URN of a ViPR SMI-S provider
 * @param systemId The id of the storage system.
 *
 * @brief Show SMI-S provider storage system
 * @return A StorageSystemRestRep reference specifying the data for the
 *         storage system.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/storage-systems/{systemId}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public StorageSystemRestRep getStorageSystem(@PathParam("id") URI id, @PathParam("systemId") URI systemId) {
    // Validate the provider.
    ArgValidator.checkFieldUriType(id, StorageProvider.class, "id");
    StorageProvider provider = _dbClient.queryObject(StorageProvider.class, id);
    ArgValidator.checkEntityNotNull(provider, id, isIdEmbeddedInURL(id));
    // Return the storage system if found.
    StringSet providerSystemURIStrs = provider.getStorageSystems();
    if (providerSystemURIStrs != null) {
        for (String providerSystemURIStr : providerSystemURIStrs) {
            if (providerSystemURIStr.equals(systemId.toString())) {
                StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, URI.create(providerSystemURIStr));
                if (storageSystem != null) {
                    return map(storageSystem);
                }
                break;
            }
        }
    }
    throw APIException.notFound.unableToFindEntityInURL(id);
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) 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