Search in sources :

Example 71 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class ProtectionSystemService method deleteProtectionSystem.

/**
 * Deactivate protection system, this will move it to a "marked-for-delete" state.
 * It will be deleted in the next iteration of garbage collector
 *
 * @param id the URN of a ViPR protection system
 * @brief Delete protection system
 * @return No data returned in response body
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response deleteProtectionSystem(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, ProtectionSystem.class, "id");
    ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, id);
    ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
    // Check to make sure there are no volumes associated with this protection system
    List<ProtectionSet> protectionSetsToDelete = new ArrayList<ProtectionSet>();
    if (checkForVolumes(id, protectionSetsToDelete)) {
        // don't allow the delete protection system if there are volumes
        throw APIException.badRequests.unableToDeactivateDueToDependencies(id);
    }
    // delete any empty protection sets
    _dbClient.markForDeletion(protectionSetsToDelete);
    // Side-effect: RPSiteArray entries need to be cleaned up so placement and connectivity feeds are correct
    // Mark all of the RPSiteArray entries associated with this protection system for deletion
    URIQueryResultList sitelist = new URIQueryResultList();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getRPSiteArrayProtectionSystemConstraint(id.toString()), sitelist);
    Iterator<URI> it = sitelist.iterator();
    while (it.hasNext()) {
        URI rpSiteArrayId = it.next();
        RPSiteArray siteArray = _dbClient.queryObject(RPSiteArray.class, rpSiteArrayId);
        if (siteArray != null) {
            _dbClient.markForDeletion(siteArray);
        }
    }
    _dbClient.markForDeletion(system);
    auditOp(OperationTypeEnum.DELETE_PROTECTION_SYSTEM, true, null, system.getId().toString());
    return Response.ok().build();
}
Also used : RPSiteArray(com.emc.storageos.db.client.model.RPSiteArray) ProtectionSet(com.emc.storageos.db.client.model.ProtectionSet) ArrayList(java.util.ArrayList) MapProtectionSystem(com.emc.storageos.api.mapper.functions.MapProtectionSystem) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 72 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission in project coprhd-controller by CoprHD.

the class ProtectionSystemService method updateProtectionSystem.

/**
 * Allows the user to update credentials for a manually created protection systems.
 *
 * @param id the URN of a ViPR protection system
 * @param param The protection system details to update.
 *
 * @brief Update protection system credentials
 * @return A ProtectionSystemRestRep reference specifying the protection system
 *         data.
 *
 * @throws InternalException When an error occurs discovering the protection
 *             system.
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep updateProtectionSystem(@PathParam("id") URI id, ProtectionSystemUpdateRequestParam param) throws InternalException {
    ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, id);
    ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
    // and Compatibility Status.
    if (!system.getIpAddress().equals(param.getIpAddress())) {
        system.setMajorVersion("");
        system.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.UNKNOWN.toString());
    }
    // Update the IP, port, username, and password with the new incoming values
    system.setIpAddress(param.getIpAddress());
    system.setPortNumber(param.getPortNumber());
    system.setUsername(param.getUserName());
    system.setPassword(param.getPassword());
    // Must force a discover during an update.
    system.setLastDiscoveryRunTime(new Long(0));
    // Make necessary changes to the protection system's cluster->varray assignments
    modifyClusterVarrayAssignments(system, param.getVarrayChanges());
    // Persist the object changes
    _dbClient.persistObject(system);
    auditOp(OperationTypeEnum.UPDATE_PROTECTION_SYSTEM, true, null, system.getId().toString(), param.getIpAddress(), param.getPortNumber(), param.getUserName());
    startProtectionSystem(system);
    // execute discovery
    ProtectionController controller = getController(RPController.class, system.getSystemType());
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    String taskId = UUID.randomUUID().toString();
    tasks.add(new AsyncTask(ProtectionSystem.class, system.getId(), taskId));
    TaskList taskList = discoverProtectionSystems(tasks, controller);
    return taskList.getTaskList().iterator().next();
}
Also used : TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) MapProtectionSystem(com.emc.storageos.api.mapper.functions.MapProtectionSystem) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) ProtectionController(com.emc.storageos.protectioncontroller.ProtectionController) 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 73 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission 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 74 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission 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 75 with CheckPermission

use of com.emc.storageos.security.authorization.CheckPermission 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)

Aggregations

CheckPermission (com.emc.storageos.security.authorization.CheckPermission)566 Produces (javax.ws.rs.Produces)512 Path (javax.ws.rs.Path)487 POST (javax.ws.rs.POST)240 Consumes (javax.ws.rs.Consumes)215 GET (javax.ws.rs.GET)194 URI (java.net.URI)185 Operation (com.emc.storageos.db.client.model.Operation)105 ArrayList (java.util.ArrayList)97 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)93 PUT (javax.ws.rs.PUT)85 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)69 Volume (com.emc.storageos.db.client.model.Volume)68 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)65 TaskList (com.emc.storageos.model.TaskList)61 FileShare (com.emc.storageos.db.client.model.FileShare)56 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)54 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)53 NamedURI (com.emc.storageos.db.client.model.NamedURI)47 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)46