Search in sources :

Example 86 with StorageProvider

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

the class HostService method createHostArrayAffinityTasks.

/**
 * Create array affinity tasks for hosts.
 *
 * @param hostIds
 *            the hosts whose preferred systems need to be discovered
 */
public TaskList createHostArrayAffinityTasks(List<URI> hostIds) {
    TaskList taskList = new TaskList();
    String taskId = UUID.randomUUID().toString();
    String jobType = "";
    Map<URI, List<URI>> providerToSystemsMap = new HashMap<URI, List<URI>>();
    Map<URI, String> providerToSystemTypeMap = new HashMap<URI, String>();
    List<URI> sysURIs = _dbClient.queryByType(StorageSystem.class, true);
    Iterator<StorageSystem> storageSystems = _dbClient.queryIterativeObjects(StorageSystem.class, sysURIs);
    while (storageSystems.hasNext()) {
        StorageSystem systemObj = storageSystems.next();
        if (systemObj == null) {
            _log.warn("StorageSystem is no longer in the DB. It could have been deleted or decommissioned");
            continue;
        }
        if (systemObj.deviceIsType(Type.vmax) || systemObj.deviceIsType(Type.vnxblock) || systemObj.deviceIsType(Type.xtremio)) {
            if (systemObj.getActiveProviderURI() == null || NullColumnValueGetter.getNullURI().equals(systemObj.getActiveProviderURI())) {
                _log.info("Skipping {} Job : StorageSystem {} does not have an active provider", jobType, systemObj.getLabel());
                continue;
            }
            StorageProvider provider = _dbClient.queryObject(StorageProvider.class, systemObj.getActiveProviderURI());
            if (provider == null || provider.getInactive()) {
                _log.info("Skipping {} Job : StorageSystem {} does not have a valid active provider", jobType, systemObj.getLabel());
                continue;
            }
            List<URI> systemIds = providerToSystemsMap.get(provider.getId());
            if (systemIds == null) {
                systemIds = new ArrayList<URI>();
                providerToSystemsMap.put(provider.getId(), systemIds);
                providerToSystemTypeMap.put(provider.getId(), systemObj.getSystemType());
            }
            systemIds.add(systemObj.getId());
        } else if (systemObj.deviceIsType(Type.unity)) {
            List<URI> systemIds = new ArrayList<URI>();
            systemIds.add(systemObj.getId());
            providerToSystemsMap.put(systemObj.getId(), systemIds);
            providerToSystemTypeMap.put(systemObj.getId(), systemObj.getSystemType());
        } else {
            _log.info("Skip unsupported system {}, system type {}", systemObj.getLabel(), systemObj.getSystemType());
            continue;
        }
    }
    for (Map.Entry<URI, List<URI>> entry : providerToSystemsMap.entrySet()) {
        List<URI> systemIds = entry.getValue();
        BlockController controller = getController(BlockController.class, providerToSystemTypeMap.get(entry.getKey()));
        DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new StorageSystemService.ArrayAffinityJobExec(controller));
        ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>();
        tasks.add(new ArrayAffinityAsyncTask(StorageSystem.class, systemIds, hostIds, taskId));
        taskList.getTaskList().addAll(scheduler.scheduleAsyncTasks(tasks).getTaskList());
    }
    return taskList;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BlockController(com.emc.storageos.volumecontroller.BlockController) TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ArrayList(java.util.ArrayList) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) UnManagedExportMaskList(com.emc.storageos.model.block.UnManagedExportMaskList) UnManagedVolumeList(com.emc.storageos.model.block.UnManagedVolumeList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) InitiatorList(com.emc.storageos.model.host.InitiatorList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) HostList(com.emc.storageos.model.host.HostList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) LinkedList(java.util.LinkedList) IpInterfaceList(com.emc.storageos.model.host.IpInterfaceList) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 87 with StorageProvider

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

the class StorageProviderService method getStorageSystem.

/**
 * Allows the user to get data for the storage system with the passed system
 * id that is associated with the storage provider with the passed provider
 * id.
 *
 * @param id the URN of a ViPR Storage provider
 * @param systemId The id of the storage system.
 *
 * @brief Show Storage 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));
    ArgValidator.checkFieldUriType(systemId, StorageSystem.class, "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) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 88 with StorageProvider

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

the class StorageProviderService method registerStorageProvider.

/**
 * Register Storage Provider
 *
 * @param param
 * @brief Define a new storage provider
 * @return TaskResponse
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep registerStorageProvider(StorageProviderCreateParam param) throws ControllerException {
    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.checkFieldRange(param.getPortNumber(), 1, 65535, "port_number");
    if (storageDriverManager == null || !storageDriverManager.isDriverManaged(param.getInterfaceType())) {
        // check this only for providers which are not managed by drivers
        ArgValidator.checkFieldValueFromEnum(param.getInterfaceType(), "interface_type", StorageProvider.InterfaceType.class);
    }
    String providerKey = param.getIpAddress() + "-" + param.getPortNumber();
    List<StorageProvider> providers = CustomQueryUtility.getActiveStorageProvidersByProviderId(_dbClient, providerKey);
    if (providers != null && !providers.isEmpty()) {
        throw APIException.badRequests.invalidParameterStorageProviderAlreadyRegistered(providerKey);
    }
    // Set the SSL parameter
    Boolean useSSL = param.getUseSSL();
    if (useSSL == null) {
        useSSL = StorageProviderCreateParam.USE_SSL_DEFAULT;
    }
    StorageProvider provider = new StorageProvider();
    provider.setId(URIUtil.createId(StorageProvider.class));
    provider.setLabel(param.getName());
    provider.setIPAddress(param.getIpAddress());
    provider.setPortNumber(param.getPortNumber());
    provider.setUserName(param.getUserName());
    provider.setPassword(param.getPassword());
    provider.setUseSSL(useSSL);
    provider.setInterfaceType(param.getInterfaceType());
    provider.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
    provider.setConnectionStatus(ConnectionStatus.INITIALIZING.name());
    provider.setSecondaryUsername(param.getSecondaryUsername());
    provider.setSecondaryPassword(param.getSecondaryPassword());
    provider.setSecondaryURL(param.getSecondaryURL());
    provider.setElementManagerURL(param.getElementManagerURL());
    if (param.getSioCLI() != null) {
        // TODO: Validate the input?
        provider.addKey(StorageProvider.GlobalKeys.SIO_CLI.name(), param.getSioCLI());
    }
    if (StorageProvider.InterfaceType.ibmxiv.name().equalsIgnoreCase(provider.getInterfaceType())) {
        provider.setManufacturer("IBM");
        // For XIV, Secondary manager URL would hold HSM URL and it is expected that these values are provided during create
        verifySecondaryParams(param.getSecondaryURL());
        if (null != param.getSecondaryUsername()) {
            ArgValidator.checkFieldNotEmpty(param.getSecondaryUsername(), "secondary_username");
        }
        if (null != param.getSecondaryPassword()) {
            ArgValidator.checkFieldNotEmpty(param.getSecondaryPassword(), "secondary_password");
        }
    }
    _dbClient.createObject(provider);
    auditOp(OperationTypeEnum.REGISTER_STORAGEPROVIDER, true, null, provider.getLabel(), provider.getId().toString(), provider.getIPAddress(), provider.getPortNumber(), provider.getUserName(), provider.getInterfaceType());
    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());
    log.debug("controller.getClass().getName() :{}", controller.getClass().getName());
    log.debug("controller.getClass().getSimpleName() :{}", controller.getClass().getSimpleName());
    /**
     * Creates MonitoringJob token for vnxblock/vmax, hds, cinder and IBM XIV device on zooKeeper queue
     */
    // TODO : If all interface types have monitoring impl class added (scaleIO is missing),
    // this check can be removed.
    String interfaceType = provider.getInterfaceType();
    if (StorageProvider.InterfaceType.hicommand.name().equalsIgnoreCase(interfaceType) || StorageProvider.InterfaceType.smis.name().equalsIgnoreCase(interfaceType) || StorageProvider.InterfaceType.cinder.name().equalsIgnoreCase(interfaceType) || StorageProvider.InterfaceType.ibmxiv.name().equalsIgnoreCase(interfaceType)) {
        controller.startMonitoring(new AsyncTask(StorageProvider.class, provider.getId(), taskId), getSystemTypeByInterface(interfaceType));
    }
    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) MapStorageProvider(com.emc.storageos.api.mapper.functions.MapStorageProvider) 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 89 with StorageProvider

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

the class StorageProviderService 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.
 *
 * @param id the URN of a ViPR Storage provider
 *
 * @brief List Storage 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) 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) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 90 with StorageProvider

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

the class StorageSystemService method deleteStorageSystem.

/**
 * Remove a storage system. The method would remove the storage system from the
 * system control and will remove all resources associated with the storage system from the database.
 * Note that resources (pools, ports, volumes, etc.) are not removed from the storage system physically,
 * but become unavailable for the user.
 *
 * @param id the URN of a ViPR storage system
 * @prereq none
 * @brief Delete storage system
 * @return An asynchronous task.
 *
 * @throws DatabaseException When an error occurs querying the database.
 */
@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 TaskResourceRep deleteStorageSystem(@PathParam("id") URI id) throws DatabaseException {
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, id);
    ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.UNREGISTERED.toString().equals(system.getRegistrationStatus())) {
        throw APIException.badRequests.cannotDeactivateStorageSystem();
    }
    // Ensure the storage system has no active RecoverPoint volumes under management.
    if (RPHelper.containsActiveRpVolumes(id, _dbClient)) {
        throw APIException.badRequests.cannotDeactivateStorageSystemActiveRpVolumes();
    }
    if (DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS.toString().equals(system.getDiscoveryStatus()) || DiscoveredDataObject.DataCollectionJobStatus.SCHEDULED.toString().equals(system.getDiscoveryStatus())) {
        throw APIException.serviceUnavailable.cannotDeactivateStorageSystemWhileInDiscover(system.getId());
    }
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(StorageSystem.class, system.getId(), taskId, ResourceOperationTypeEnum.DELETE_STORAGE_SYSTEM);
    // Otherwise, the created decommissioned object will not be cleared when the provider is removed and added back.
    if (StringUtils.isNotBlank(system.getNativeGuid()) && system.isStorageSystemManagedByProvider() && !NullColumnValueGetter.isNullURI(system.getActiveProviderURI())) {
        DecommissionedResource oldStorage = null;
        List<URI> oldResources = _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getDecommissionedResourceIDConstraint(id.toString()));
        if (oldResources != null) {
            List<DecommissionedResource> objects = _dbClient.queryObject(DecommissionedResource.class, oldResources);
            for (DecommissionedResource decomObj : objects) {
                if (!decomObj.getInactive()) {
                    oldStorage = decomObj;
                    break;
                }
            }
        }
        if (oldStorage == null) {
            oldStorage = new DecommissionedResource();
            oldStorage.setNativeGuid(system.getNativeGuid());
            oldStorage.setType(TypeMap.getCFName(StorageSystem.class));
            oldStorage.setUser(getUserFromContext().getName());
            oldStorage.setDecommissionedId(system.getId());
            oldStorage.setLabel(system.getLabel());
            oldStorage.setId(URIUtil.createId(DecommissionedResource.class));
            _dbClient.createObject(oldStorage);
        }
        StorageProvider provider = _dbClient.queryObject(StorageProvider.class, system.getActiveProviderURI());
        if (provider != null) {
            StringSet providerDecomSys = provider.getDecommissionedSystems();
            if (providerDecomSys == null) {
                providerDecomSys = new StringSet();
                provider.setDecommissionedSystems(providerDecomSys);
            }
            providerDecomSys.add(oldStorage.getId().toString());
            _dbClient.updateObject(provider);
        }
    }
    PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), system, _retry_attempts, taskId, 60);
    return toTask(system, taskId, op);
}
Also used : StringSet(com.emc.storageos.db.client.model.StringSet) DecommissionedResource(com.emc.storageos.db.client.model.DecommissionedResource) Operation(com.emc.storageos.db.client.model.Operation) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) 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)

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