Search in sources :

Example 16 with AbstractChangeTrackingSet

use of com.emc.storageos.db.client.model.AbstractChangeTrackingSet 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)

Example 17 with AbstractChangeTrackingSet

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

the class BlockVolumeCGIngestDecorator method decorateCG.

@Override
public void decorateCG(BlockConsistencyGroup cg, Collection<BlockObject> associatedObjects, IngestionRequestContext requestContext, UnManagedVolume unManagedVolume) throws Exception {
    if (null == associatedObjects || associatedObjects.isEmpty()) {
        logger.info("No associated BlockObject's found to decorate for cg {}", cg.getLabel());
        return;
    }
    for (BlockObject blockObj : associatedObjects) {
        StringSetMap systemCGs = cg.getSystemConsistencyGroups();
        // No entries yet in the system consistency groups list. That's OK, we'll create it.
        if (null == systemCGs || systemCGs.isEmpty()) {
            cg.setSystemConsistencyGroups(new StringSetMap());
        }
        // This volume is not in a CG of this type
        if (NullColumnValueGetter.isNullValue(blockObj.getReplicationGroupInstance())) {
            logger.info("BlockObject {} doesn't have replicationGroup name {}. No need to set system cg information.", blockObj.getNativeGuid());
            continue;
        }
        boolean found = false;
        // Look through the existing entries in the CG and see if we find a match.
        for (Entry<String, AbstractChangeTrackingSet<String>> systemCGEntry : systemCGs.entrySet()) {
            if (systemCGEntry.getKey().equalsIgnoreCase(blockObj.getStorageController().toString())) {
                if (systemCGEntry.getValue().contains(blockObj.getReplicationGroupInstance())) {
                    logger.info(String.format("Found BlockObject %s,%s system details in cg %s", blockObj.getNativeGuid(), blockObj.getReplicationGroupInstance(), cg.getLabel()));
                    found = true;
                    break;
                }
            }
        }
        // If we didn't find this storage:cg combo, let's add it.
        if (!found) {
            logger.info(String.format("Adding BlockObject %s/%s in CG %s", blockObj.getNativeGuid(), blockObj.getReplicationGroupInstance(), cg.getLabel()));
            cg.addSystemConsistencyGroup(blockObj.getStorageController().toString(), blockObj.getReplicationGroupInstance());
        }
        if (!cg.getTypes().contains(Types.LOCAL.toString())) {
            cg.getTypes().add(Types.LOCAL.toString());
        }
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) BlockObject(com.emc.storageos.db.client.model.BlockObject) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Example 18 with AbstractChangeTrackingSet

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

the class RecoverPointScheduler method isInternalSiteAssociatedWithVarray.

/**
 * Is the cluster associated with the virtual array (and its networks) configured?
 *
 * @param sourceVarray source varray
 * @param candidateProtectionSystem protection system
 * @return
 */
private boolean isInternalSiteAssociatedWithVarray(VirtualArray varray, String internalSiteName, ProtectionSystem candidateProtectionSystem) {
    if (candidateProtectionSystem == null || candidateProtectionSystem.getSiteInitiators() == null) {
        _log.warn(String.format("RP Placement : Disqualifying use of RP Cluster %s because it was not found to have any discovered initiators." + " Re-run discovery.", internalSiteName));
        return false;
    }
    String translatedInternalSiteName = candidateProtectionSystem.getRpSiteNames().get(internalSiteName);
    // Check to see if this RP Cluster is assigned to this virtual array.
    StringSetMap siteAssignedVirtualArrays = candidateProtectionSystem.getSiteAssignedVirtualArrays();
    if (siteAssignedVirtualArrays != null && !siteAssignedVirtualArrays.isEmpty()) {
        // Store a list of the valid internal sites for this varray.
        List<String> associatedInternalSitesForThisVarray = new ArrayList<String>();
        // varray.
        for (Map.Entry<String, AbstractChangeTrackingSet<String>> entry : siteAssignedVirtualArrays.entrySet()) {
            // Check to see if this entry contains the varray
            if (entry.getValue().contains(varray.getId().toString())) {
                // This varray has been explicitly associated to this internal site
                String associatedInternalSite = entry.getKey();
                _log.info(String.format("RP Placement : VirtualArray [%s] has been explicitly associated with RP Cluster [%s]", varray.getLabel(), candidateProtectionSystem.getRpSiteNames().get(associatedInternalSite)));
                associatedInternalSitesForThisVarray.add(associatedInternalSite);
            }
        }
        // return false as we can't use it this internal site.
        if (!associatedInternalSitesForThisVarray.isEmpty() && !associatedInternalSitesForThisVarray.contains(internalSiteName)) {
            // The user has isolated this varray to specific internal sites and this is not one of them.
            _log.info(String.format("RP Placement : Disqualifying use of RP Cluster : %s because there are assigned associations to " + "varrays and varray : %s is not one of them.", translatedInternalSiteName, varray.getLabel()));
            return false;
        }
    }
    for (String endpoint : candidateProtectionSystem.getSiteInitiators().get(internalSiteName)) {
        if (endpoint == null) {
            continue;
        }
        if (RPHelper.isInitiatorInVarray(varray, endpoint, dbClient)) {
            _log.info(String.format("RP Placement : Qualifying use of RP Cluster : %s because it is not excluded explicitly and there's " + "connectivity to varray : %s.", translatedInternalSiteName, varray.getLabel()));
            return true;
        }
    }
    _log.info(String.format("RP Placement : Disqualifying use of RP Cluster : %s because it was not found to be connected to a Network " + "that belongs to varray : %s", translatedInternalSiteName, varray.getLabel()));
    return false;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringMap(com.emc.storageos.db.client.model.StringMap) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Example 19 with AbstractChangeTrackingSet

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

the class RPHelper method getBackendPortInitiators.

/**
 * Returns a set of all RP ports as their related Initiator URIs.
 *
 * @param dbClient - database client instance
 * @return a Set of Initiator URIs
 */
public static Set<URI> getBackendPortInitiators(DbClient dbClient) {
    _log.info("Finding backend port initiators for all RP systems");
    Set<URI> initiators = new HashSet<URI>();
    List<URI> rpSystemUris = dbClient.queryByType(ProtectionSystem.class, true);
    List<ProtectionSystem> rpSystems = dbClient.queryObject(ProtectionSystem.class, rpSystemUris);
    for (ProtectionSystem rpSystem : rpSystems) {
        for (Entry<String, AbstractChangeTrackingSet<String>> rpSitePorts : rpSystem.getSiteInitiators().entrySet()) {
            for (String port : rpSitePorts.getValue()) {
                Initiator initiator = ExportUtils.getInitiator(port, dbClient);
                if (initiator != null) {
                    // Review: OK to reduce to debug level
                    _log.info("Adding initiator " + initiator.getId() + " with port: " + port);
                    initiators.add(initiator.getId());
                }
            }
        }
    }
    return initiators;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) HashSet(java.util.HashSet) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Aggregations

AbstractChangeTrackingSet (com.emc.storageos.db.client.model.AbstractChangeTrackingSet)19 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)11 URI (java.net.URI)10 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 HashMap (java.util.HashMap)7 AbstractChangeTrackingMap (com.emc.storageos.db.client.model.AbstractChangeTrackingMap)4 DataObject (com.emc.storageos.db.client.model.DataObject)4 StringMap (com.emc.storageos.db.client.model.StringMap)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 AbstractChangeTrackingSetMap (com.emc.storageos.db.client.model.AbstractChangeTrackingSetMap)3 NamedURI (com.emc.storageos.db.client.model.NamedURI)3 ProtectionSystem (com.emc.storageos.db.client.model.ProtectionSystem)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 HashSet (java.util.HashSet)3 List (java.util.List)3 AbstractSerializableNestedObject (com.emc.storageos.db.client.model.AbstractSerializableNestedObject)2 BlockObject (com.emc.storageos.db.client.model.BlockObject)2 Initiator (com.emc.storageos.db.client.model.Initiator)2