Search in sources :

Example 11 with AbstractChangeTrackingSet

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

the class BasePermissionsHelper method convertToACLEntries.

/**
 * Converts StringSetMap of acls into a list of ACLEntry as used by the API
 *
 * @param acls to be converted into the ACLEntry list.
 * @return the converted ACLEntry list.
 */
public static List<ACLEntry> convertToACLEntries(StringSetMap acls) {
    List<ACLEntry> assignments = new ArrayList<ACLEntry>();
    if (CollectionUtils.isEmpty(acls)) {
        return assignments;
    }
    for (Map.Entry<String, AbstractChangeTrackingSet<String>> ace : acls.entrySet()) {
        PermissionsKey rowKey = new PermissionsKey();
        rowKey.parseFromString(ace.getKey());
        ACLEntry entry = new ACLEntry();
        if (rowKey.getType().equals(PermissionsKey.Type.GROUP)) {
            entry.setGroup(rowKey.getValue());
        } else if (rowKey.getType().equals(PermissionsKey.Type.SID)) {
            entry.setSubjectId(rowKey.getValue());
        } else if (rowKey.getType().equals(PermissionsKey.Type.TENANT)) {
            entry.setTenant(rowKey.getValue());
        }
        for (String priv : ace.getValue()) {
            // skip owner
            if (priv.equalsIgnoreCase(ACL.OWN.toString())) {
                continue;
            }
            entry.getAces().add(priv);
        }
        if (!entry.getAces().isEmpty()) {
            assignments.add(entry);
        }
    }
    return assignments;
}
Also used : ACLEntry(com.emc.storageos.model.auth.ACLEntry) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Example 12 with AbstractChangeTrackingSet

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

the class ExternalDeviceExportOperations method prepareCapabilitiesForAddInitiators.

private void prepareCapabilitiesForAddInitiators(ExportPathParams pathParams, StringSetMap existingZoningMap, URI varrayURI, List<com.emc.storageos.db.client.model.Initiator> initiators, StorageCapabilities capabilities) {
    int driverMaxPath;
    StringSetMap zoningMap = new StringSetMap();
    // Calculate existing paths (without new initiators).
    int existingPaths = 0;
    List<URI> initiatorUris = URIUtil.toUris(initiators);
    for (Map.Entry<String, AbstractChangeTrackingSet<String>> entry : existingZoningMap.entrySet()) {
        if (!initiatorUris.contains(URIUtil.uri(entry.getKey()))) {
            zoningMap.put(entry.getKey(), entry.getValue());
        }
    }
    Map<com.emc.storageos.db.client.model.Initiator, List<com.emc.storageos.db.client.model.StoragePort>> assignments = blockScheduler.generateInitiatorsToStoragePortsMap(zoningMap, varrayURI);
    existingPaths = assignments.values().size();
    log.info("Existing path number in the export mask is {}", existingPaths);
    // Otherwise we allocate the difference between max paths and existing paths
    if (existingPaths + pathParams.getPathsPerInitiator() > pathParams.getMaxPaths()) {
        // we always need at least path-per-initiator ports
        driverMaxPath = pathParams.getPathsPerInitiator();
    } else {
        driverMaxPath = pathParams.getMaxPaths() - existingPaths;
    }
    // We assume that masking view meets min path before new initiators are added. We pass ppi as a minPath
    // to driver, so we can zone at least one new initiator.
    ExportPathsServiceOption numPath = new ExportPathsServiceOption(pathParams.getPathsPerInitiator(), driverMaxPath);
    List<ExportPathsServiceOption> exportPathParams = new ArrayList<>();
    exportPathParams.add(numPath);
    CommonStorageCapabilities commonCapabilities = new CommonStorageCapabilities();
    commonCapabilities.setExportPathParams(exportPathParams);
    capabilities.setCommonCapabilitis(commonCapabilities);
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) CommonStorageCapabilities(com.emc.storageos.storagedriver.storagecapabilities.CommonStorageCapabilities) ArrayList(java.util.ArrayList) URI(java.net.URI) ExportPathsServiceOption(com.emc.storageos.storagedriver.storagecapabilities.ExportPathsServiceOption) Initiator(com.emc.storageos.storagedriver.model.Initiator) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) 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 13 with AbstractChangeTrackingSet

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

the class VDCRoleMigrationCallback method removeRoleFromRootTenant.

/**
 * remove VDC roles from rootTenantOrg
 *
 * @param vdc
 * @param rootTenant
 */
private void removeRoleFromRootTenant(VirtualDataCenter vdc, TenantOrg rootTenant) {
    StringSetMap vdcRoles = vdc.getRoleAssignments();
    for (Map.Entry<String, AbstractChangeTrackingSet<String>> roleAssignment : vdcRoles.entrySet()) {
        String uid = roleAssignment.getKey();
        Iterator<String> itr = roleAssignment.getValue().iterator();
        while (itr.hasNext()) {
            String role = itr.next();
            rootTenant.removeRole(uid, role);
        }
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) Map(java.util.Map) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Example 14 with AbstractChangeTrackingSet

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

the class DBClient method rebuildIndex.

public boolean rebuildIndex(URI id, Class clazz) {
    boolean runResult = false;
    try {
        DataObject queryObject = queryObject(id, clazz);
        if (queryObject != null) {
            DataObject newObject = queryObject.getClass().newInstance();
            newObject.trackChanges();
            ConvertUtils.register(new CalendarConverter(null), Calendar.class);
            ConvertUtils.register(new DateConverter(null), Date.class);
            BeanUtilsBean notNull = new NullAwareBeanUtilsBean();
            notNull.copyProperties(newObject, queryObject);
            // special change tracking for customized types
            BeanInfo bInfo;
            try {
                bInfo = Introspector.getBeanInfo(clazz);
            } catch (IntrospectionException ex) {
                log.error("Unexpected exception getting bean info", ex);
                throw new RuntimeException("Unexpected exception getting bean info", ex);
            }
            PropertyDescriptor[] pds = bInfo.getPropertyDescriptors();
            for (PropertyDescriptor pd : pds) {
                Object val = pd.getReadMethod().invoke(newObject);
                if (val instanceof AbstractChangeTrackingSet) {
                    AbstractChangeTrackingSet valueSet = (AbstractChangeTrackingSet) val;
                    valueSet.markAllForOverwrite();
                } else if (val instanceof AbstractChangeTrackingMap) {
                    AbstractChangeTrackingMap valueMap = (AbstractChangeTrackingMap) val;
                    valueMap.markAllForOverwrite();
                } else if (val instanceof AbstractChangeTrackingSetMap) {
                    AbstractChangeTrackingSetMap valueMap = (AbstractChangeTrackingSetMap) val;
                    Set<String> keys = valueMap.keySet();
                    if (keys != null) {
                        Iterator<String> it = keys.iterator();
                        while (it.hasNext()) {
                            String key = it.next();
                            AbstractChangeTrackingSet valueSet = valueMap.get(key);
                            valueSet.markAllForOverwrite();
                        }
                    }
                }
            }
            _dbClient.updateObject(newObject);
            logMsg(String.format("Successfully rebuild index for %s in cf %s", id, clazz));
            runResult = true;
        } else {
            logMsg(String.format("Could not find data object record for %s in cf %s, no need to rebuild index. Mark as success too.", id, clazz));
            runResult = true;
        }
    } catch (Exception e) {
        logMsg(String.format("Error when rebuilding index for %s in cf %s", id, clazz), true, e);
    }
    return runResult;
}
Also used : DateConverter(org.apache.commons.beanutils.converters.DateConverter) PropertyDescriptor(java.beans.PropertyDescriptor) AbstractChangeTrackingSetMap(com.emc.storageos.db.client.model.AbstractChangeTrackingSetMap) BeanInfo(java.beans.BeanInfo) IntrospectionException(java.beans.IntrospectionException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) IOException(java.io.IOException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) CalendarConverter(org.apache.commons.beanutils.converters.CalendarConverter) BeanUtilsBean(org.apache.commons.beanutils.BeanUtilsBean) DataObject(com.emc.storageos.db.client.model.DataObject) AbstractChangeTrackingMap(com.emc.storageos.db.client.model.AbstractChangeTrackingMap) DataObject(com.emc.storageos.db.client.model.DataObject) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet)

Example 15 with AbstractChangeTrackingSet

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

the class NetworkScheduler method getZoningRemoveTargets.

/**
 * Generate the NetworkFCZoneInfo structures representing the zone/volume duples
 * that are fed to the actual zoning code to remove zones.
 * @param zoningParams -- Collection of NetworkZoningParam that contains initiator information
 * @param volumeURIs -- Optional Collection of volumes being affected by the zoning operation.
 * If null, the zoningParams.getVolumes() is used instead, which comes from the ExportMask volumes keyset.
 * @return list of NetworkFCZonInfos representing zones and FCZoneReferences to be removed
 */
public List<NetworkFCZoneInfo> getZoningRemoveTargets(Collection<NetworkZoningParam> zoningParams, Collection<URI> volumeURIs) {
    List<NetworkFCZoneInfo> zoningTargets = new ArrayList<NetworkFCZoneInfo>();
    // and add them to the zoningTargets result list.
    for (NetworkZoningParam zoningParam : zoningParams) {
        URI varray = zoningParam.getVirtualArray();
        _log.info(String.format("Generating remove zoning targets for ExportMask %s (%s)", zoningParam.getMaskName(), zoningParam.getMaskId()));
        // validate the initiators are FC, and calculate the zone information
        for (Map.Entry<String, AbstractChangeTrackingSet<String>> entry : zoningParam.getZoningMap().entrySet()) {
            String initiatorId = entry.getKey();
            Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(initiatorId));
            if (initiator == null || initiator.getInactive()) {
                _log.info("Initiator inactive: " + initiatorId);
                continue;
            }
            if (StorageProtocol.block2Transport(initiator.getProtocol()) != Transport.FC) {
                _log.info(String.format("Initiator not FC %s %s", initiator.getInitiatorPort(), initiatorId));
                continue;
            }
            Set<String> portSet = entry.getValue();
            if (portSet == null || portSet.isEmpty()) {
                _log.info(String.format("No ports in zoningMap for initiator %s %s", initiator.getInitiatorPort(), initiatorId));
                continue;
            }
            List<URI> exportGroupURIs = new ArrayList<URI>();
            exportGroupURIs.add(zoningParam.getExportGroupId());
            if (zoningParam.getAlternateExportGroupIds() != null) {
                exportGroupURIs.addAll(zoningParam.getAlternateExportGroupIds());
            }
            // Calculate the zone information for each initiator/port combination
            for (String portId : portSet) {
                // Calculate the zone information
                List<NetworkFCZoneInfo> zoneInfos = unexportVolumes(varray, (volumeURIs != null ? volumeURIs : zoningParam.getVolumes()), exportGroupURIs, URI.create(portId), formatWWN(initiator.getInitiatorPort()), zoningParam.hasExistingVolumes());
                if (zoneInfos != null) {
                    zoningTargets.addAll(zoneInfos);
                }
            }
        }
    }
    return zoningTargets;
}
Also used : NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) URI(java.net.URI) 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)

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