Search in sources :

Example 41 with VirtualDataCenter

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");
    }
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) OperationException(com.netflix.astyanax.connectionpool.exceptions.OperationException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) UnknownHostException(java.net.UnknownHostException)

Example 42 with VirtualDataCenter

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()));
}
Also used : Project(com.emc.storageos.db.client.model.Project) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) DbClient(com.emc.storageos.db.client.DbClient) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) ArrayList(java.util.ArrayList) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) Test(org.junit.Test)

Example 43 with VirtualDataCenter

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;
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 44 with VirtualDataCenter

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;
}
Also used : ArrayList(java.util.ArrayList) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI) GeoException(com.emc.storageos.security.geo.exceptions.GeoException)

Example 45 with VirtualDataCenter

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());
    }
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter)

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