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");
}
}
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;
}
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;
}
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;
}
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");
}
Aggregations