Search in sources :

Example 36 with VirtualDataCenter

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

the class VdcControllerTest method testAddToMultipleVdc.

/**
 * Adding vdc4 to a connected vdc1/2/3
 */
// Test hanging in IDE and "gradlew test"
@Test
public void testAddToMultipleVdc() throws Exception {
    // create a mockdb with 3 existing vdc
    dbClient.buildInitData(3);
    // Treat as Geo strategy options already set to remove Cassandra, preventing calling to
    // remote JMX
    dbClient.getGeoStrategyOptions().put("vdc4", "abc");
    VirtualDataCenter vdc1 = dbClient.vdcList.get(0);
    VirtualDataCenter newVdc = newVdcForAdding("vdc4");
    // dbClient.vdcList.add(newVdc);
    log.info("Testing connect new vdc {} to 3 existing vdc {}", newVdc.getShortId(), vdc1.getId());
    Properties vdcInfo = GeoServiceHelper.getVDCInfo(newVdc);
    String reqId = "taskid-0001";
    addTask(reqId, vdc1.getId());
    // Start execute vdc connect
    vdcController.connectVdc(vdc1, reqId, Arrays.asList(new Object[] { vdcInfo }));
    // Verify result
    URI newVDCId = null;
    Iterator<URI> vdcIter = dbClient.queryByType(VirtualDataCenter.class, true).iterator();
    while (vdcIter.hasNext()) {
        URI id = vdcIter.next();
        String vdcId = URIUtil.parseVdcIdFromURI(id.toASCIIString());
        if (vdcId.equals("vdc4")) {
            newVDCId = id;
            break;
        }
    }
    Assert.assertNotNull(newVDCId);
    VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, newVDCId);
    Assert.assertNotNull(vdc);
    Assert.assertTrue(vdc.getShortId().equals("vdc4"));
    Assert.assertNotNull(vdc.getHostCount());
    Assert.assertNotNull(vdc.getHostIPv4AddressesMap());
    Assert.assertTrue(clientManager.client.countForSyncCall == 3);
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) DataObject(com.emc.storageos.db.client.model.DataObject) TestGeoObject(com.emc.storageos.db.client.model.TestGeoObject) Properties(java.util.Properties) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Test(org.junit.Test)

Example 37 with VirtualDataCenter

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

the class VdcControllerTest method testRemoveVdcInUsePreCheck.

/**
 * Remove vdc2 from vdc1
 */
// Test hanging in IDE and "gradlew test"
@Test
public void testRemoveVdcInUsePreCheck() throws Exception {
    // create a mock db with 2 existing vdc
    dbClient.buildInitData(2);
    VirtualDataCenter vdc1 = dbClient.vdcList.get(0);
    VirtualDataCenter vdc2 = dbClient.vdcList.get(1);
    log.info("Testing precheck for removing vdc2 {} from vdc1 {}", vdc2.getId(), vdc1.getId());
    VirtualDataCenterInUse vdcInUse = new VirtualDataCenterInUse();
    vdcInUse.setId(vdc2.getId());
    vdcInUse.setInUse(true);
    dbClient.createObject(vdcInUse);
    // Start execute vdc remove
    try {
        String reqId = "remove-taskid-0003";
        addTask(reqId, vdc2.getId());
        vdcController.removeVdc(vdc2, reqId, null);
        Assert.assertTrue("Precheck should throw an exception", false);
    } catch (Exception ex) {
        log.error("precheck error ", ex);
        Assert.assertTrue(ex instanceof FatalGeoException);
    }
}
Also used : VirtualDataCenterInUse(com.emc.storageos.db.client.model.VirtualDataCenterInUse) VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) FatalGeoException(com.emc.storageos.security.geo.exceptions.FatalGeoException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) BindException(java.net.BindException) ConnectionException(com.netflix.astyanax.connectionpool.exceptions.ConnectionException) GeoException(com.emc.storageos.security.geo.exceptions.GeoException) FatalGeoException(com.emc.storageos.security.geo.exceptions.FatalGeoException) Test(org.junit.Test)

Example 38 with VirtualDataCenter

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

the class VdcControllerTest method testRemoveVdcFromThreeSiteGeo.

/**
 * Remove vdc3 from vdc1/vdc2
 */
// Test hanging in IDE and "gradlew test"
@Test
public void testRemoveVdcFromThreeSiteGeo() throws Exception {
    // create a mock db with 3 existing vdc
    dbClient.buildInitData(3);
    VirtualDataCenter vdc1 = dbClient.vdcList.get(0);
    VirtualDataCenter vdc2 = dbClient.vdcList.get(1);
    VirtualDataCenter vdc3 = dbClient.vdcList.get(1);
    log.info("Testing remove vdc3 {} ", vdc3.getId());
    // Start execute vdc remove
    vdc3.setConnectionStatus(VirtualDataCenter.ConnectionStatus.REMOVING);
    dbClient.updateAndReindexObject(vdc3);
    String reqId = "remove-taskid-0003";
    addTask(reqId, vdc3.getId());
    vdcController.removeVdc(vdc3, reqId, null);
    // Verify result
    Assert.assertTrue(dbClient.vdcList.size() == 2);
    VirtualDataCenter vdc = dbClient.queryObject(VirtualDataCenter.class, vdc1.getId());
    Assert.assertNotNull(vdc);
    Assert.assertTrue(vdc.getShortId().equals("vdc1"));
    Assert.assertNotNull(vdc.getHostCount());
    Assert.assertNotNull(vdc.getHostIPv4AddressesMap());
    Assert.assertTrue(clientManager.client.countForSyncCall == 2);
    // vdc3 should be removed from local db
    vdc = dbClient.queryObject(VirtualDataCenter.class, vdc3.getId());
    Assert.assertNull(vdc);
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) Test(org.junit.Test)

Example 39 with VirtualDataCenter

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

the class VdcUtil method buildUrnMap.

private static void buildUrnMap() {
    if (rebuildVdcIdMap) {
        // When running unit test, prevents NPEs when creating URIs
        if (dbClient == null) {
            return;
        }
        synchronized (vdcIdMap) {
            if (rebuildVdcIdMap) {
                log.info("Rebuilding the vdcIdMap from the database");
                List<URI> vdcIds = dbClient.queryByType(VirtualDataCenter.class, true);
                Iterator<VirtualDataCenter> vdcIter = dbClient.queryIterativeObjects(VirtualDataCenter.class, vdcIds);
                localVdc = null;
                vdcIdMap.clear();
                while (vdcIter.hasNext()) {
                    VirtualDataCenter vdc = vdcIter.next();
                    vdcIdMap.put(vdc.getShortId(), vdc.getId());
                    if (Boolean.TRUE.equals(vdc.getLocal())) {
                        localVdc = vdc;
                    }
                }
                if (!vdcIdMap.isEmpty()) {
                    rebuildVdcIdMap = false;
                }
            }
        }
    }
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) URI(java.net.URI)

Example 40 with VirtualDataCenter

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

the class SchemaUtil method insertMyVdcInfo.

/**
 * Insert vdc info of current site
 */
private void insertMyVdcInfo(DbClient dbClient) throws UnknownHostException {
    if (!getCfMap().containsKey(TypeMap.getDoType(VirtualDataCenter.class).getCF().getName())) {
        _log.error("Unable to find VirtualDataCenter CF in current keyspace");
        return;
    }
    VirtualDataCenter localVdc = queryLocalVdc(dbClient);
    if (localVdc != null) {
        return;
    }
    _log.info("insert vdc info of current site...");
    VirtualDataCenter vdc = new VirtualDataCenter();
    vdc.setId(URIUtil.createVirtualDataCenterId(_vdcShortId));
    vdc.setShortId(_vdcShortId);
    vdc.setLabel(_vdcShortId);
    vdc.setConnectionStatus(VirtualDataCenter.ConnectionStatus.ISOLATED);
    vdc.setRepStatus(VirtualDataCenter.GeoReplicationStatus.REP_NONE);
    // timestamp
    vdc.setVersion(new Date().getTime());
    vdc.setApiEndpoint(_vdcEndpoint);
    vdc.setLocal(true);
    dbClient.createObject(vdc);
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) Date(java.util.Date)

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