use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.
the class SchemaUtil method queryLocalVdc.
private VirtualDataCenter queryLocalVdc(DbClient dbClient) {
// all vdc info stored in local db
try {
_log.debug("my vdcid: " + _vdcShortId);
URIQueryResultList list = new URIQueryResultList();
AlternateIdConstraint constraints = AlternateIdConstraint.Factory.getVirtualDataCenterByShortIdConstraint(_vdcShortId);
dbClient.queryByConstraint(constraints, list);
if (list.iterator().hasNext()) {
URI vdcId = list.iterator().next();
VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, vdcId);
return vdc;
} else {
_log.info("vdc resource query returned no results");
return null;
}
} catch (DatabaseException ex) {
_log.error("failed querying for vdc resource", ex);
// Throw an DatabaseException and retry
throw ex;
} catch (Exception ex) {
_log.error("unexpected error during querying for vdc info", ex);
// throw IllegalStateExcpetion and stop
throw new IllegalStateException("vdc resource query failed");
}
}
use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.
the class VdcUtilTest method testVdcUtil.
@Test
public void testVdcUtil() {
VirtualDataCenter localVdc = null;
DbClient dbClient = getDbClient();
Iterator<URI> vdcs = dbClient.queryByType(VirtualDataCenter.class, true).iterator();
if (vdcs.hasNext()) {
localVdc = dbClient.queryObject(VirtualDataCenter.class, vdcs.next());
} else {
Assert.fail("no VDC found in database");
}
if (vdcs.hasNext()) {
Assert.fail("multiple VDC's found in database after initial bootstap");
}
Assert.assertEquals(localVdc.getId(), VdcUtil.getLocalVdc().getId());
Assert.assertEquals(localVdc.getShortId(), VdcUtil.getLocalShortVdcId());
Assert.assertEquals(localVdc.getId(), VdcUtil.getVdcUrn(localVdc.getShortId()));
VirtualDataCenter remoteVdc1 = new VirtualDataCenter();
remoteVdc1.setId(URIUtil.createId(VirtualDataCenter.class));
remoteVdc1.setLocal(Boolean.FALSE);
remoteVdc1.setShortId("vdc2");
VirtualDataCenter remoteVdc2 = new VirtualDataCenter();
remoteVdc2.setId(URIUtil.createId(VirtualDataCenter.class));
remoteVdc2.setLocal(Boolean.FALSE);
remoteVdc2.setShortId("vdc3");
List<VirtualDataCenter> vdcList = new ArrayList<VirtualDataCenter>();
vdcList.add(remoteVdc1);
vdcList.add(remoteVdc2);
dbClient.createObject(vdcList);
VdcUtil.invalidateVdcUrnCache();
Assert.assertEquals(localVdc.getId(), VdcUtil.getLocalVdc().getId());
Assert.assertEquals(localVdc.getShortId(), VdcUtil.getLocalShortVdcId());
Assert.assertEquals(localVdc.getId(), VdcUtil.getVdcUrn(localVdc.getShortId()));
Assert.assertEquals(remoteVdc1.getId(), VdcUtil.getVdcUrn(remoteVdc1.getShortId()));
Assert.assertEquals(remoteVdc2.getId(), VdcUtil.getVdcUrn(remoteVdc2.getShortId()));
VirtualArray va = new VirtualArray();
va.setId(URIUtil.createId(VirtualArray.class));
Assert.assertFalse(VdcUtil.isRemoteObject(va));
vdcList.clear();
remoteVdc1.setLocal(Boolean.TRUE);
localVdc.setLocal(Boolean.FALSE);
vdcList.add(remoteVdc1);
vdcList.add(localVdc);
dbClient.updateAndReindexObject(vdcList);
VdcUtil.invalidateVdcUrnCache();
Assert.assertTrue(VdcUtil.isRemoteObject(va));
URI globalId = URIUtil.createId(Project.class);
URI localId = URIUtil.createId(FileShare.class);
Assert.assertTrue(VdcUtil.getVdcId(Project.class, globalId).toString().equals(VdcUtil.getLocalShortVdcId()));
Assert.assertTrue(VdcUtil.getVdcId(FileShare.class, localId).toString().equals(VdcUtil.getLocalShortVdcId()));
}
use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.
the class GeoDependencyChecker method hasDisconnectedVdc.
private boolean hasDisconnectedVdc() {
boolean hasDiconnVdc = false;
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);
if (vDC.getConnectionStatus() == VirtualDataCenter.ConnectionStatus.DISCONNECTED || vDC.getConnectionStatus() == VirtualDataCenter.ConnectionStatus.DISCONNECTING) {
log.info("Geo dependency check, vdc {} is under disconnect status", vDC.getShortId());
hasDiconnVdc = true;
}
}
return hasDiconnVdc;
}
use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.
the class GeoUpgradeVoter method getUnstableVdcs.
/**
* Return a list of unstable/non-connected VDCs if any.
* Throw different exceptions accordingly if such a VDC is found.
*/
private List<String> getUnstableVdcs() {
List<URI> vdcIdIter = dbClient.queryByType(VirtualDataCenter.class, true);
List<String> unstableVdcs = new ArrayList<>();
for (URI vdcId : vdcIdIter) {
VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, vdcId);
// Iterated each remote vdc to check stability
if (vdc.getRepStatus().equals(VirtualDataCenter.GeoReplicationStatus.REP_ALL) && !vdc.getLocal()) {
if (!VirtualDataCenter.ConnectionStatus.CONNECTED.equals(vdc.getConnectionStatus())) {
throw GeoException.fatals.vdcNotConnected(vdc.getShortId());
}
try {
GeoServiceClient client = geoClientCache.getGeoClient(vdc.getShortId());
if (!client.isVdcStable()) {
log.info("VDC {} is not stable", vdc.getShortId());
unstableVdcs.add(vdc.getShortId());
}
} catch (Exception ex) {
log.error("Unexpected exception during VDC stability check", ex);
throw GeoException.fatals.vdcNotReachable(vdc.getShortId());
}
}
}
return unstableVdcs;
}
use of com.emc.storageos.db.client.model.VirtualDataCenter in project coprhd-controller by CoprHD.
the class IPsecManager method verifyIPsecOpAllowableOverGeo.
private void verifyIPsecOpAllowableOverGeo() {
if (!drUtil.isMultivdc()) {
return;
}
// Other VDCs are stable
List<String> vdcIds = drUtil.getOtherVdcIds();
for (String peerVdcId : vdcIds) {
if (!geoClientManager.getGeoClient(peerVdcId).isVdcStable()) {
log.error(vdcIds + " is not stable");
throw APIException.serviceUnavailable.vdcNotStable(peerVdcId);
}
}
// No ongoing jobs
VdcUtil.setDbClient(dbClient);
VirtualDataCenter localVdc = VdcUtil.getLocalVdc();
VirtualDataCenter.ConnectionStatus vdcStatus = localVdc.getConnectionStatus();
if (!vdcStatus.equals(VirtualDataCenter.ConnectionStatus.CONNECTED) && !vdcStatus.equals(VirtualDataCenter.ConnectionStatus.ISOLATED)) {
throw APIException.serviceUnavailable.vdcOngingJob(localVdc.getShortId(), vdcStatus.name());
}
}
Aggregations