Search in sources :

Example 6 with VirtualDataCenter

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

the class DBClient method verifyVdcConfigs.

private void verifyVdcConfigs(List<VdcConfig> vdcConfigs) {
    if (vdcConfigs == null) {
        throw new RuntimeException("Null vdc config list");
    }
    List<URI> vdcUrisFromDb = getVdcUrisFromDb();
    if (vdcConfigs.size() + 1 != vdcUrisFromDb.size()) {
        String errMsg = String.format("vdc config count from CF VdcOpLog (%d) " + "should be 1 less than the vdc count from CF VirtualDataCenter (%d).", vdcConfigs.size(), vdcUrisFromDb.size());
        log.error(errMsg);
        System.err.println(errMsg);
        System.err.println(REGEN_RECOVER_FILE_MSG);
        throw new RuntimeException("vdc count mismatch");
    }
    List<URI> vdcUrisFromConfig = getVdcUrisFromConfig(vdcConfigs);
    List<URI> failedVdcUris = new ArrayList<>(vdcUrisFromDb);
    failedVdcUris.removeAll(vdcUrisFromConfig);
    if (failedVdcUris.size() != 1) {
        String errMsg = String.format("Not all the vdc's from the vdc config list (%s) " + " are found from CF VirtualDataCenter (%s)", vdcUrisFromConfig.toString(), vdcUrisFromDb.toString());
        log.error(errMsg);
        System.err.println(errMsg);
        System.err.println(REGEN_RECOVER_FILE_MSG);
        throw new RuntimeException("vdc URI mismatch");
    }
    VirtualDataCenter vdc = _dbClient.queryObject(VirtualDataCenter.class, failedVdcUris.get(0));
    VirtualDataCenter.ConnectionStatus status = vdc.getConnectionStatus();
    if (status != VirtualDataCenter.ConnectionStatus.CONNECT_FAILED) {
        String errMsg = String.format("vdc %s should be in state CONNECT_FAILED but " + "actually is %s.", failedVdcUris.get(0), vdc.getConnectionStatus());
        log.error(errMsg);
        System.err.println(errMsg);
        System.err.println(REGEN_RECOVER_FILE_MSG);
        throw new RuntimeException("wrong vdc connection status");
    }
}
Also used : ArrayList(java.util.ArrayList) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 7 with VirtualDataCenter

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

the class BasePermissionsHelper method checkForActiveVDCRoleAssignmentsUsingUserGroup.

/**
 * Checks whether the given the user group is present in the local vdc's
 * role-assignment or not
 *
 * @param label to check if any vdc role-assignments uses user group or not.
 * @return set of URI's VDCs that uses the user group.
 */
public Set<URI> checkForActiveVDCRoleAssignmentsUsingUserGroup(String label) {
    Set<URI> vdcUsingUserGroup = null;
    VirtualDataCenter vdc = VdcUtil.getLocalVdc();
    if (vdc == null) {
        _log.error("Could not find local VDC");
        return vdcUsingUserGroup;
    }
    if (CollectionUtils.isEmpty(vdc.getRoleAssignments())) {
        _log.debug("Role assignments are not configured for vdc {}", vdc.getLabel());
        return vdcUsingUserGroup;
    }
    vdcUsingUserGroup = new HashSet<URI>();
    Set<String> roleAssignmentKeys = vdc.getRoleAssignments().keySet();
    if (checkUserGroupWithPermissionKeys(label, roleAssignmentKeys)) {
        vdcUsingUserGroup.add(vdc.getId());
    }
    return vdcUsingUserGroup;
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 8 with VirtualDataCenter

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

the class GeoClientCacheManager method lookupVdc.

private VirtualDataCenter lookupVdc(String shortVdcId) {
    // to refresh the cache in case it's called after a new VDC added.
    dbClient.invalidateVdcUrnCache();
    URI vdcURN = dbClient.getVdcUrn(shortVdcId);
    // TODO: convert to the appropriate ViPR exception
    if (vdcURN == null) {
        throw new IllegalArgumentException("unknown vdc id " + shortVdcId);
    }
    VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, vdcURN);
    // TODO: convert to the proper ViPR exception
    if (vdc == null) {
        throw new IllegalArgumentException("vdc does not exist: " + vdcURN);
    }
    return vdc;
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 9 with VirtualDataCenter

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

the class GeoDependencyChecker method checkDependencies.

/**
 * checks to see if any references exist for this uri
 * uses dependency list created from relational indices
 *
 * @param uri id of the DataObject
 * @param type DataObject class name
 * @param onlyActive if true, checks for active references only (expensive)
 * @param excludeTypes optional list of classes that can be excluded as dependency
 * @return null if no references exist on this uri, return the type of the dependency if exist
 */
public String checkDependencies(URI uri, Class<? extends DataObject> type, boolean onlyActive, List<Class<? extends DataObject>> excludeTypes) {
    String depMsg = localDependencyChecker.checkDependencies(uri, type, true, excludeTypes);
    if (depMsg != null || KeyspaceUtil.isLocal(type)) {
        return depMsg;
    }
    // If there is any vdc under disconnect status, do not check dependency, return ""
    if (hasDisconnectedVdc()) {
        return "";
    }
    List<URI> vDCIds = dbClient.queryByType(VirtualDataCenter.class, true);
    VirtualDataCenter vDC = null;
    for (URI vDCId : vDCIds) {
        if (vDCId.equals(VdcUtil.getLocalVdc().getId())) {
            // skip local vDC
            continue;
        }
        vDC = dbClient.queryObject(VirtualDataCenter.class, vDCId);
        GeoServiceClient client = geoClientManager.getGeoClient(vDC.getShortId());
        log.debug("Query Geo server={}", client.getServiceURI());
        try {
            String dependency = client.checkDependencies(type, uri, true);
            if (!dependency.isEmpty()) {
                log.info("Can't GC {} because depends on {} on {}", new Object[] { uri, dependency, vDCId });
                return dependency;
            }
        } catch (Exception e) {
            log.error("Failed to query depenedency for {} on {} e=", new Object[] { uri, vDC.getShortId(), e });
            log.error("so assume it has dependency");
            return "";
        }
    }
    log.debug("Geo object {} can be GC", uri);
    return null;
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) DataObject(com.emc.storageos.db.client.model.DataObject) URI(java.net.URI)

Example 10 with VirtualDataCenter

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

the class GeoServiceHelper method backupOperationVdc.

public static void backupOperationVdc(DbClient dbClient, GeoServiceJob.JobType jobType, URI operatedVdc, String operationParam) {
    VdcOpLog op = new VdcOpLog();
    op.setId(URIUtil.createId(VdcOpLog.class));
    op.setOperationType(jobType.toString());
    op.setOperatedVdc(operatedVdc);
    try {
        byte[] paramBytes = SerializerUtils.serializeAsByteArray(operationParam);
        op.setOperationParam(paramBytes);
    } catch (Exception e) {
        throw InternalServerErrorException.internalServerErrors.genericApisvcError("Internal error when backup vdc config info", e);
    }
    List<VirtualDataCenter> vdcList = new ArrayList();
    List<URI> ids = dbClient.queryByType(VirtualDataCenter.class, true);
    for (URI id : ids) {
        VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, id);
        if (vdc != null) {
            if (vdc.getLocal() || (!vdc.getLocal() && vdc.getRepStatus() != VirtualDataCenter.GeoReplicationStatus.REP_NONE)) {
                log.info("Add vdc {} {} to backup list", vdc.getId().toString(), vdc.getShortId());
                vdcList.add(vdc);
            }
        }
    }
    try {
        byte[] vdcBytes = SerializerUtils.serializeAsByteArray(vdcList);
        op.setVdcConfigInfo(vdcBytes);
    } catch (Exception e) {
        throw InternalServerErrorException.internalServerErrors.genericApisvcError("Internal error when backup vdc config info", e);
    }
    dbClient.createObject(op);
    log.info("Backup vdc config info succeed");
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) ArrayList(java.util.ArrayList) URI(java.net.URI) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VdcOpLog(com.emc.storageos.db.client.model.VdcOpLog)

Aggregations

VirtualDataCenter (com.emc.storageos.db.client.model.VirtualDataCenter)80 URI (java.net.URI)47 ArrayList (java.util.ArrayList)20 VdcConfig (com.emc.storageos.geomodel.VdcConfig)14 GeoException (com.emc.storageos.security.geo.exceptions.GeoException)13 Test (org.junit.Test)10 Site (com.emc.storageos.coordinator.client.model.Site)7 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)7 VdcConfigSyncParam (com.emc.storageos.geomodel.VdcConfigSyncParam)7 FatalGeoException (com.emc.storageos.security.geo.exceptions.FatalGeoException)7 NamedURI (com.emc.storageos.db.client.model.NamedURI)6 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)5 Produces (javax.ws.rs.Produces)5 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)4 DataObject (com.emc.storageos.db.client.model.DataObject)4 TestGeoObject (com.emc.storageos.db.client.model.TestGeoObject)4 ConnectionException (com.netflix.astyanax.connectionpool.exceptions.ConnectionException)4 KeyStoreException (java.security.KeyStoreException)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4