Search in sources :

Example 6 with ObjectNamespace

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

the class DiscoveryUtils method checkNamespacesNotVisible.

/**
 * Dump & remove deleted namespaces in object storage
 *
 * @param discoveredNamespaces
 * @param dbClient
 * @param storageSystemId
 */
public static void checkNamespacesNotVisible(List<ObjectNamespace> discoveredNamespaces, DbClient dbClient, URI storageSystemId) {
    // Get the namespaces previousy discovered
    URIQueryResultList objNamespaceURIs = new URIQueryResultList();
    dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceObjectNamespaceConstraint(storageSystemId), objNamespaceURIs);
    Iterator<URI> objNamespaceIter = objNamespaceURIs.iterator();
    List<URI> existingNamespacesURI = new ArrayList<URI>();
    while (objNamespaceIter.hasNext()) {
        existingNamespacesURI.add(objNamespaceIter.next());
    }
    List<URI> discoveredNamespacesURI = new ArrayList<URI>();
    for (ObjectNamespace namespace : discoveredNamespaces) {
        discoveredNamespacesURI.add(namespace.getId());
    }
    // Present in existing but not in discovered; remove them
    Set<URI> namespacesDiff = Sets.difference(new HashSet<URI>(existingNamespacesURI), new HashSet<URI>(discoveredNamespacesURI));
    if (!namespacesDiff.isEmpty()) {
        Iterator<ObjectNamespace> objNamespaceIt = dbClient.queryIterativeObjects(ObjectNamespace.class, namespacesDiff, true);
        while (objNamespaceIt.hasNext()) {
            ObjectNamespace namespace = objNamespaceIt.next();
            // Namespace is not associated with tenant
            if (namespace.getTenant() == null) {
                _log.info("Object Namespace not visible & getting deleted {} : {}", namespace.getNativeId(), namespace.getId());
                namespace.setDiscoveryStatus(DiscoveredDataObject.DiscoveryStatus.NOTVISIBLE.name());
                namespace.setInactive(true);
            }
            dbClient.updateObject(namespace);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) ObjectNamespace(com.emc.storageos.db.client.model.ObjectNamespace) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 7 with ObjectNamespace

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

the class StorageSystemService method getAllObjectNamespaces.

/**
 * Gets all object namespaces for the registered storage system with the passed id
 *
 * @param id the URN of a ViPR storage system.
 *
 * @brief List object storage namespaces
 * @return A reference to a ObjectNamespaceList
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/object-namespaces")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public ObjectNamespaceList getAllObjectNamespaces(@PathParam("id") URI id) {
    // Make sure storage system is registered.
    ArgValidator.checkFieldUriType(id, StorageSystem.class, "id");
    StorageSystem system = queryResource(id);
    ArgValidator.checkEntity(system, id, isIdEmbeddedInURL(id));
    if (!StorageSystem.Type.ecs.toString().equals(system.getSystemType())) {
        throw APIException.badRequests.invalidParameterURIInvalid("id", id);
    }
    ObjectNamespaceList objNamespaceList = new ObjectNamespaceList();
    URIQueryResultList objNamespaceURIs = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceObjectNamespaceConstraint(id), objNamespaceURIs);
    Iterator<URI> ecsNsIter = objNamespaceURIs.iterator();
    while (ecsNsIter.hasNext()) {
        URI nsURI = ecsNsIter.next();
        ObjectNamespace namespace = _dbClient.queryObject(ObjectNamespace.class, nsURI);
        if (namespace != null && !namespace.getInactive()) {
            objNamespaceList.getNamespaces().add(toNamedRelatedResource(namespace, namespace.getNativeGuid()));
        }
    }
    return objNamespaceList;
}
Also used : ObjectNamespaceList(com.emc.storageos.model.object.ObjectNamespaceList) URI(java.net.URI) ObjectNamespace(com.emc.storageos.db.client.model.ObjectNamespace) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) 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 8 with ObjectNamespace

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

the class TenantsService method createSubTenant.

/**
 * Create subtenant
 *
 * @param param Subtenant create parameter
 * @param id the URN of a ViPR Tenant
 * @prereq An authentication provider needs to support the domain used in the mappings
 * @brief Create subtenant
 * @return Subtenant details
 */
@POST
@Path("/{id}/subtenants")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SECURITY_ADMIN })
public TenantOrgRestRep createSubTenant(@PathParam("id") URI id, TenantCreateParam param) {
    ObjectNamespace namesp = null;
    boolean namespModified = false;
    TenantOrg parent = getTenantById(id, true);
    if (!TenantOrg.isRootTenant(parent)) {
        throw APIException.badRequests.parentTenantIsNotRoot();
    }
    ArgValidator.checkFieldNotEmpty(param.getLabel(), "name");
    checkForDuplicateName(param.getLabel(), TenantOrg.class, id, "parentTenant", _dbClient);
    TenantOrg subtenant = new TenantOrg();
    subtenant.setId(URIUtil.createId(TenantOrg.class));
    subtenant.setParentTenant(new NamedURI(parent.getId(), param.getLabel()));
    subtenant.setLabel(param.getLabel());
    subtenant.setDescription(param.getDescription());
    if (param.getNamespace() != null) {
        checkForDuplicateNamespace(param.getNamespace());
        subtenant.setNamespace(param.getNamespace());
        // Update tenant info in respective namespace CF
        List<URI> allNamespaceURI = _dbClient.queryByType(ObjectNamespace.class, true);
        Iterator<ObjectNamespace> nsItr = _dbClient.queryIterativeObjects(ObjectNamespace.class, allNamespaceURI);
        while (nsItr.hasNext()) {
            namesp = nsItr.next();
            if (subtenant.getNamespace().equalsIgnoreCase(namesp.getNativeId())) {
                namesp.setTenant(subtenant.getId());
                namesp.setMapped(true);
                // There could be exceptions ahead; update the db at end
                namespModified = true;
                break;
            }
        }
    }
    if (null == param.getUserMappings() || param.getUserMappings().isEmpty()) {
        throw APIException.badRequests.requiredParameterMissingOrEmpty("user_mappings");
    } else {
        checkUserMappingAttribute(param.getUserMappings());
        addUserMappings(subtenant, param.getUserMappings(), getUserFromContext());
    }
    // add creator as tenant admin
    subtenant.addRole(new PermissionsKey(PermissionsKey.Type.SID, getUserFromContext().getName()).toString(), Role.TENANT_ADMIN.toString());
    // perform user tenant check before persistent
    mapOutProviderTenantCheck(subtenant);
    if (namespModified) {
        _dbClient.updateObject(namesp);
    }
    _dbClient.createObject(subtenant);
    // To Do - add attributes to the set of attributes to pull from AD/LDAP
    recordOperation(OperationTypeEnum.CREATE_TENANT, parent.getId(), subtenant);
    return map(subtenant);
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) PermissionsKey(com.emc.storageos.security.authorization.PermissionsKey) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) ObjectNamespace(com.emc.storageos.db.client.model.ObjectNamespace) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) 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 9 with ObjectNamespace

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

the class TenantsService method setTenant.

/**
 * Update info for tenant or subtenant
 *
 * @param param Tenant update parameter
 * @param id the URN of a ViPR Tenant/Subtenant
 * @prereq If modifying user mappings, an authentication provider needs to support the domain used in the mappings
 * @brief Update tenant or subtenant
 * @return the updated Tenant/Subtenant instance
 */
@PUT
@Path("/{id}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN, Role.SECURITY_ADMIN })
public TenantOrgRestRep setTenant(@PathParam("id") URI id, TenantUpdateParam param) {
    TenantOrg tenant = getTenantById(id, true);
    ObjectNamespace namesp = null;
    boolean namespModified = false;
    ObjectNamespace oldNamesp = null;
    boolean oldNamespModified = false;
    if (param.getLabel() != null && !param.getLabel().isEmpty()) {
        if (!tenant.getLabel().equalsIgnoreCase(param.getLabel())) {
            checkForDuplicateName(param.getLabel(), TenantOrg.class, tenant.getParentTenant().getURI(), "parentTenant", _dbClient);
        }
        tenant.setLabel(param.getLabel());
        NamedURI parent = tenant.getParentTenant();
        if (parent != null) {
            parent.setName(param.getLabel());
            tenant.setParentTenant(parent);
        }
    }
    if (param.getDescription() != null) {
        tenant.setDescription(param.getDescription());
    }
    if (!StringUtils.isEmpty(param.getNamespace())) {
        if (!param.getNamespace().equals(tenant.getNamespace())) {
            checkForDuplicateNamespace(param.getNamespace());
        }
        if (!StringUtils.isEmpty(tenant.getNamespace()) && !"null".equals(tenant.getNamespace())) {
            if (!tenant.getNamespace().equalsIgnoreCase(param.getNamespace())) {
                List<Class<? extends DataObject>> excludeTypes = Lists.newArrayList();
                excludeTypes.add(ObjectNamespace.class);
                // Though we are not deleting need to check no dependencies on this tenant
                ArgValidator.checkReference(TenantOrg.class, id, checkForDelete(tenant, excludeTypes));
            }
        }
        String oldNamespace = tenant.getNamespace();
        tenant.setNamespace(param.getNamespace());
        // Update tenant info in respective namespace CF
        List<URI> allNamespaceURI = _dbClient.queryByType(ObjectNamespace.class, true);
        Iterator<ObjectNamespace> nsItr = _dbClient.queryIterativeObjects(ObjectNamespace.class, allNamespaceURI);
        while (nsItr.hasNext()) {
            namesp = nsItr.next();
            if (namesp.getNativeId().equalsIgnoreCase(param.getNamespace())) {
                namesp.setTenant(tenant.getId());
                namesp.setMapped(true);
                // There is a chance of exceptions ahead; hence updated db at the end
                namespModified = true;
                break;
            }
        }
        // removing link between tenant and the old namespace
        List<URI> namespaceURIs = _dbClient.queryByType(ObjectNamespace.class, true);
        Iterator<ObjectNamespace> nsItrToUnMap = _dbClient.queryIterativeObjects(ObjectNamespace.class, namespaceURIs);
        while (nsItrToUnMap.hasNext()) {
            oldNamesp = nsItrToUnMap.next();
            if (oldNamesp.getNativeId().equalsIgnoreCase(oldNamespace)) {
                oldNamesp.setMapped(false);
                oldNamespModified = true;
                break;
            }
        }
    }
    if (param.getDetachNamespace()) {
        List<Class<? extends DataObject>> excludeTypes = Lists.newArrayList();
        excludeTypes.add(ObjectNamespace.class);
        // Though we are not deleting need to check no dependencies on this tenant
        ArgValidator.checkReference(TenantOrg.class, id, checkForDelete(tenant, excludeTypes));
        String oldNamespace = tenant.getNamespace();
        tenant.setNamespace(NullColumnValueGetter.getNullStr());
        // Update tenant info in respective namespace CF
        List<URI> allNamespaceURI = _dbClient.queryByType(ObjectNamespace.class, true);
        Iterator<ObjectNamespace> nsItr = _dbClient.queryIterativeObjects(ObjectNamespace.class, allNamespaceURI);
        while (nsItr.hasNext()) {
            namesp = nsItr.next();
            if (namesp.getNativeId().equalsIgnoreCase(oldNamespace)) {
                namesp.setMapped(false);
                // There is a chance of exceptions ahead; hence updated db at the end
                namespModified = true;
                break;
            }
        }
    }
    if (!isUserMappingEmpty(param)) {
        // only SecurityAdmin can modify user-mapping
        if (!_permissionsHelper.userHasGivenRole((StorageOSUser) sc.getUserPrincipal(), null, Role.SECURITY_ADMIN)) {
            throw ForbiddenException.forbidden.onlySecurityAdminsCanModifyUserMapping();
        }
        if (null != param.getUserMappingChanges().getRemove() && !param.getUserMappingChanges().getRemove().isEmpty() && null != tenant.getUserMappings()) {
            checkUserMappingAttribute(param.getUserMappingChanges().getRemove());
            List<UserMapping> remove = UserMapping.fromParamList(param.getUserMappingChanges().getRemove());
            StringSetMap mappingsToRemove = new StringSetMap();
            // Find the database entries to remove
            for (UserMapping mappingToRemove : remove) {
                StringSet domainMappings = tenant.getUserMappings().get(mappingToRemove.getDomain().trim());
                trimGroupAndDomainNames(mappingToRemove);
                if (null != domainMappings) {
                    for (String existingMapping : domainMappings) {
                        if (mappingToRemove.equals(UserMapping.fromString(existingMapping))) {
                            mappingsToRemove.put(mappingToRemove.getDomain(), existingMapping);
                        }
                    }
                }
            }
            // Remove the items from the tenant database object
            for (Entry<String, AbstractChangeTrackingSet<String>> mappingToRemoveSet : mappingsToRemove.entrySet()) {
                for (String mappingToRemove : mappingToRemoveSet.getValue()) {
                    tenant.removeUserMapping(mappingToRemoveSet.getKey(), mappingToRemove);
                }
            }
        }
        if (null != param.getUserMappingChanges().getAdd() && !param.getUserMappingChanges().getAdd().isEmpty()) {
            checkUserMappingAttribute(param.getUserMappingChanges().getAdd());
            addUserMappings(tenant, param.getUserMappingChanges().getAdd(), getUserFromContext());
        }
        if (!TenantOrg.isRootTenant(tenant)) {
            boolean bMappingsEmpty = true;
            for (AbstractChangeTrackingSet<String> mapping : tenant.getUserMappings().values()) {
                if (!mapping.isEmpty()) {
                    bMappingsEmpty = false;
                    break;
                }
            }
            if (bMappingsEmpty) {
                throw APIException.badRequests.requiredParameterMissingOrEmpty("user_mappings");
            }
        }
        // request contains user-mapping change, perform the check.
        mapOutProviderTenantCheck(tenant);
    }
    if (namespModified) {
        _dbClient.updateObject(namesp);
    }
    if (oldNamespModified) {
        _dbClient.updateObject(oldNamesp);
    }
    _dbClient.updateAndReindexObject(tenant);
    recordOperation(OperationTypeEnum.UPDATE_TENANT, tenant.getId(), tenant);
    return map(getTenantById(id, false));
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DataObject(com.emc.storageos.db.client.model.DataObject) UserMapping(com.emc.storageos.security.authorization.BasePermissionsHelper.UserMapping) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) StringSet(com.emc.storageos.db.client.model.StringSet) ObjectNamespace(com.emc.storageos.db.client.model.ObjectNamespace) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

ObjectNamespace (com.emc.storageos.db.client.model.ObjectNamespace)9 URI (java.net.URI)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 GET (javax.ws.rs.GET)4 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)3 ArrayList (java.util.ArrayList)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 ECSApi (com.emc.storageos.ecs.api.ECSApi)2 ECSException (com.emc.storageos.ecs.api.ECSException)2 ObjectNamespaceList (com.emc.storageos.model.object.ObjectNamespaceList)2 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)2 ECSCollectionException (com.emc.storageos.plugins.metering.ecs.ECSCollectionException)2 SMIPluginException (com.emc.storageos.plugins.metering.smis.SMIPluginException)2 URISyntaxException (java.net.URISyntaxException)2