Search in sources :

Example 71 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class InitialSetupMigrationTest method verifyResults.

@Override
protected void verifyResults() throws Exception {
    InitialSetup setup = _dbClient.queryObject(InitialSetup.class, InitialSetup.SINGLETON_ID);
    Assert.assertTrue("the InitialSetup singleton should be gone after migration", ((setup == null) || (setup.getInactive() == Boolean.TRUE)));
    Configuration config = getCoordinator().queryConfiguration(InitialSetup.CONFIG_KIND, InitialSetup.CONFIG_ID);
    Assert.assertNotNull("coordinator config  setup object should not be null", config);
    String complete = config.getConfig(InitialSetup.COMPLETE);
    Assert.assertTrue("coordinator config setup object should be marked comoplete", complete != null && complete.equals(Boolean.TRUE.toString()));
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) InitialSetup(com.emc.storageos.db.client.model.uimodels.InitialSetup)

Example 72 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method testAddStandby.

@Test
public void testAddStandby() {
    // prepare parameters for adding standby
    String name = "new-added-standby";
    String desc = "standby-site-1-description";
    String vip = "10.247.101.112";
    String username = "root";
    String password = "password";
    String uuid = "new-added-standby-site-1";
    String version = "vipr-2.4.0.0.100";
    HashMap<String, String> hostIPv4AddressMap = new HashMap<String, String>();
    hostIPv4AddressMap.put("vipr1", "10.247.101.111");
    SiteConfigRestRep config = new SiteConfigRestRep();
    config.setUuid(uuid);
    config.setVip(vip);
    config.setHostIPv4AddressMap(hostIPv4AddressMap);
    config.setHostIPv6AddressMap(new HashMap<String, String>());
    com.emc.vipr.client.core.Site site = mock(com.emc.vipr.client.core.Site.class);
    doReturn(config).when(site).getStandbyConfig();
    // mock a ViPRCoreClient with specific UUID
    ViPRCoreClient mockViPRCoreClient = mock(ViPRCoreClient.class);
    doReturn(mockViPRCoreClient).when(drService).createViPRCoreClient(vip, username, password);
    doReturn(site).when(mockViPRCoreClient).site();
    // mock a ViPRSystemClient with specific UUID
    doReturn(mockViPRSystemClient(version)).when(drService).createViPRSystemClient(vip, username, password);
    // mock a local VDC
    List<Configuration> allConfigs = new ArrayList<>();
    allConfigs.add(standbySite1.toConfiguration());
    allConfigs.add(standbySite2.toConfiguration());
    allConfigs.add(primarySite.toConfiguration());
    doReturn(allConfigs).when(coordinator).queryAllConfiguration(String.format("%s/vdc1", Site.CONFIG_KIND));
    doReturn(standbySite1.toConfiguration()).when(coordinator).queryConfiguration(String.format("%s/vdc1", Site.CONFIG_KIND), standbySite1.getUuid());
    doReturn(standbySite2.toConfiguration()).when(coordinator).queryConfiguration(String.format("%s/vdc1", Site.CONFIG_KIND), standbySite2.getUuid());
    // mock new added site
    Site newAdded = new Site();
    newAdded.setUuid(uuid);
    newAdded.setVip(vip);
    newAdded.getHostIPv4AddressMap().put("vipr1", "1.1.1.1");
    newAdded.setState(SiteState.ACTIVE);
    doReturn(newAdded.toConfiguration()).when(coordinator).queryConfiguration(String.format("%s/vdc1", Site.CONFIG_KIND), newAdded.getUuid());
    doReturn(new PropertyInfoExt()).when(coordinator).getTargetInfo(PropertyInfoExt.class);
    // mock checking and validating methods
    doNothing().when(drService).precheckForSiteNumber();
    doNothing().when(drService).precheckForStandbyAdd(any(SiteConfigRestRep.class), any(ViPRCoreClient.class));
    doNothing().when(drService).validateAddParam(any(SiteAddParam.class), any(List.class));
    doReturn(standbySite1).when(drUtil).getActiveSite();
    doReturn(secretKey).when(apiSignatureGeneratorMock).getSignatureKey(SignatureKeyType.INTERVDC_API);
    // assemble parameters, add standby
    SiteAddParam params = new SiteAddParam();
    params.setName(name);
    params.setDescription(desc);
    params.setVip(vip);
    params.setUsername(username);
    params.setPassword(password);
    SiteRestRep rep = drService.addStandby(params);
    // verify the REST response
    assertEquals(name, rep.getName());
    assertEquals(desc, rep.getDescription());
    assertEquals(vip, rep.getVipEndpoint());
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) ViPRCoreClient(com.emc.vipr.client.ViPRCoreClient) SiteRestRep(com.emc.storageos.model.dr.SiteRestRep) Configuration(com.emc.storageos.coordinator.common.Configuration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) SiteAddParam(com.emc.storageos.model.dr.SiteAddParam) PropertyInfoExt(com.emc.storageos.coordinator.client.model.PropertyInfoExt) SiteConfigRestRep(com.emc.storageos.model.dr.SiteConfigRestRep) SiteList(com.emc.storageos.model.dr.SiteList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 73 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method testPrecheckForStandbyAttach_NotPrimarySite.

@Test
public void testPrecheckForStandbyAttach_NotPrimarySite() throws Exception {
    try {
        Configuration config = new ConfigurationImpl();
        config.setConfig(Constants.CONFIG_DR_ACTIVE_SITEID, "654321");
        doReturn(config).when(coordinator).queryConfiguration(Constants.CONFIG_DR_ACTIVE_KIND, Constants.CONFIG_DR_ACTIVE_ID);
        doReturn("123456").when(coordinator).getSiteId();
        drService.precheckForStandbyAdd(standby, mockViPRCoreClient(null));
        fail();
    } catch (Exception e) {
    // ignore expected exception
    }
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) ConfigurationImpl(com.emc.storageos.coordinator.common.impl.ConfigurationImpl) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CoordinatorException(com.emc.storageos.coordinator.exceptions.CoordinatorException) Test(org.junit.Test)

Example 74 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method setUp.

@Before
public void setUp() throws Exception {
    Constructor constructor = ProductName.class.getDeclaredConstructors()[0];
    constructor.setAccessible(true);
    ProductName productName = (ProductName) constructor.newInstance();
    productName.setName("vipr");
    SoftwareVersion version = new SoftwareVersion("vipr-2.4.0.0.100");
    LinkedList<SoftwareVersion> available = new LinkedList<SoftwareVersion>();
    available.add(version);
    RepositoryInfo repositoryInfo = new RepositoryInfo(new SoftwareVersion("vipr-2.4.0.0.100"), available);
    standby = new SiteConfigRestRep();
    standby.setClusterStable(true);
    standby.setFreshInstallation(true);
    standby.setDbSchemaVersion("2.4");
    standby.setSoftwareVersion("vipr-2.4.0.0.150");
    standby.setHostIPv4AddressMap(new HashMap<String, String>());
    standby.getHostIPv4AddressMap().put("vipr1", "10.247.101.100");
    // setup standby site
    standbySite1 = new Site();
    standbySite1.setUuid("site-uuid-1");
    standbySite1.setVip("10.247.101.110");
    standbySite1.getHostIPv4AddressMap().put("vipr1", "10.247.101.111");
    standbySite1.getHostIPv4AddressMap().put("vipr2", "10.247.101.112");
    standbySite1.getHostIPv4AddressMap().put("vipr3", "10.247.101.113");
    standbySite1.setState(SiteState.STANDBY_PAUSED);
    standbySite1.setVdcShortId("vdc1");
    standbySite1.setNodeCount(1);
    standbySite2 = new Site();
    standbySite2.setUuid("site-uuid-2");
    standbySite2.setState(SiteState.STANDBY_SYNCED);
    standbySite2.setVdcShortId("vdc1");
    standbySite2.setVip("10.247.101.158");
    standbySite2.setNodeCount(1);
    standbySite3 = new Site();
    standbySite3.setUuid("site-uuid-3");
    standbySite3.setVdcShortId("fake-vdc-id");
    standbySite3.setState(SiteState.ACTIVE);
    standbySite3.setVdcShortId("vdc1");
    standbySite3.setNodeCount(1);
    primarySite = new Site();
    primarySite.setUuid("primary-site-uuid");
    primarySite.setVip("127.0.0.1");
    primarySite.setHostIPv4AddressMap(standbySite1.getHostIPv4AddressMap());
    primarySite.setHostIPv6AddressMap(standbySite1.getHostIPv6AddressMap());
    primarySite.setVdcShortId("vdc1");
    primarySite.setState(SiteState.ACTIVE);
    primarySite.setNodeCount(3);
    // mock DBClient
    dbClientMock = mock(DbClientImpl.class);
    // mock coordinator client
    coordinator = mock(CoordinatorClient.class);
    // mock ipsecconfig
    IPsecConfig ipsecConfig = mock(IPsecConfig.class);
    doReturn("ipsec-preshared-key").when(ipsecConfig).getPreSharedKey();
    drUtil = mock(DrUtil.class);
    natCheckParam = new DRNatCheckParam();
    apiSignatureGeneratorMock = mock(InternalApiSignatureKeyGenerator.class);
    try {
        KeyGenerator keyGenerator = null;
        keyGenerator = KeyGenerator.getInstance("HmacSHA256");
        secretKey = keyGenerator.generateKey();
    } catch (NoSuchAlgorithmException e) {
        fail("generate key fail");
    }
    drService = spy(new DisasterRecoveryService());
    drService.setDbClient(dbClientMock);
    drService.setCoordinator(coordinator);
    drService.setDrUtil(drUtil);
    drService.setSiteMapper(new SiteMapper());
    drService.setSysUtils(new SysUtils());
    drService.setIpsecConfig(ipsecConfig);
    drService.setApiSignatureGenerator(apiSignatureGeneratorMock);
    standbyConfig = new Site();
    standbyConfig.setUuid("standby-site-uuid-1");
    standbyConfig.setVip(standbySite1.getVip());
    standbyConfig.setHostIPv4AddressMap(standbySite1.getHostIPv4AddressMap());
    standbyConfig.setHostIPv6AddressMap(standbySite1.getHostIPv6AddressMap());
    standbyConfig.setNodeCount(3);
    doReturn(standbyConfig.getUuid()).when(coordinator).getSiteId();
    Configuration config = new ConfigurationImpl();
    config.setConfig(Constants.CONFIG_DR_ACTIVE_SITEID, primarySite.getUuid());
    doReturn(config).when(coordinator).queryConfiguration(Constants.CONFIG_DR_ACTIVE_KIND, Constants.CONFIG_DR_ACTIVE_ID);
    doReturn("2.4").when(coordinator).getCurrentDbSchemaVersion();
    doReturn(primarySite.getUuid()).when(coordinator).getSiteId();
    doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState();
    // Don't need to record audit log in UT
    doNothing().when(drService).auditDisasterRecoveryOps(any(OperationTypeEnum.class), anyString(), anyString(), anyVararg());
    doReturn(repositoryInfo).when(coordinator).getTargetInfo(RepositoryInfo.class);
    doReturn(standbySite1).when(drUtil).getSiteFromLocalVdc(standbySite1.getUuid());
    doReturn(standbySite2).when(drUtil).getSiteFromLocalVdc(standbySite2.getUuid());
    doThrow(CoordinatorException.retryables.cannotFindSite(NONEXISTENT_ID)).when(drUtil).getSiteFromLocalVdc(NONEXISTENT_ID);
    doReturn(primarySite).when(drUtil).getSiteFromLocalVdc(primarySite.getUuid());
    SiteNetworkState siteNetworkState = new SiteNetworkState();
    siteNetworkState.setNetworkHealth(SiteNetworkState.NetworkHealth.GOOD);
    doReturn(siteNetworkState).when(drUtil).getSiteNetworkState(any(String.class));
    CoordinatorClientInetAddressMap addressMap = new CoordinatorClientInetAddressMap();
    addressMap.setDualInetAddress(DualInetAddress.fromAddresses("10.247.101.110", ""));
    doReturn(addressMap).when(coordinator).getInetAddessLookupMap();
    InterProcessLock lock = mock(InterProcessLock.class);
    doReturn(lock).when(coordinator).getLock(anyString());
    doReturn(true).when(lock).acquire(anyInt(), any(TimeUnit.class));
    doNothing().when(lock).release();
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) IPsecConfig(com.emc.storageos.security.ipsec.IPsecConfig) ProductName(com.emc.storageos.coordinator.client.model.ProductName) Configuration(com.emc.storageos.coordinator.common.Configuration) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) Matchers.anyString(org.mockito.Matchers.anyString) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) TimeUnit(java.util.concurrent.TimeUnit) SiteConfigRestRep(com.emc.storageos.model.dr.SiteConfigRestRep) KeyGenerator(javax.crypto.KeyGenerator) InternalApiSignatureKeyGenerator(com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator) ConfigurationImpl(com.emc.storageos.coordinator.common.impl.ConfigurationImpl) InternalApiSignatureKeyGenerator(com.emc.storageos.security.authentication.InternalApiSignatureKeyGenerator) RepositoryInfo(com.emc.storageos.coordinator.client.model.RepositoryInfo) Constructor(java.lang.reflect.Constructor) SiteMapper(com.emc.storageos.api.mapper.SiteMapper) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil) LinkedList(java.util.LinkedList) SysUtils(com.emc.storageos.services.util.SysUtils) SoftwareVersion(com.emc.storageos.coordinator.client.model.SoftwareVersion) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) DRNatCheckParam(com.emc.storageos.model.dr.DRNatCheckParam) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) SiteNetworkState(com.emc.storageos.coordinator.client.model.SiteNetworkState) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) Before(org.junit.Before)

Example 75 with Configuration

use of com.emc.storageos.coordinator.common.Configuration in project coprhd-controller by CoprHD.

the class DisasterRecoveryService method isFreshInstallation.

protected boolean isFreshInstallation() {
    Configuration setupConfig = coordinator.queryConfiguration(InitialSetup.CONFIG_KIND, InitialSetup.CONFIG_ID);
    boolean freshInstall = (setupConfig == null) || !Boolean.parseBoolean(setupConfig.getConfig(InitialSetup.COMPLETE));
    log.info("Fresh installation {}", freshInstall);
    boolean hasDataInDB = dbClient.hasUsefulData();
    log.info("Has useful data in DB {}", hasDataInDB);
    return freshInstall && !hasDataInDB;
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration)

Aggregations

Configuration (com.emc.storageos.coordinator.common.Configuration)87 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)16 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)11 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)9 IOException (java.io.IOException)9 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)8 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)8 Site (com.emc.storageos.coordinator.client.model.Site)7 UnknownHostException (java.net.UnknownHostException)7 KeeperException (org.apache.zookeeper.KeeperException)7 PropertyInfoMapper.decodeFromString (com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)3 MigrationStatus (com.emc.storageos.coordinator.client.model.MigrationStatus)2 PropertyInfoExt (com.emc.storageos.coordinator.client.model.PropertyInfoExt)2 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)2 CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)2 SiteConfigRestRep (com.emc.storageos.model.dr.SiteConfigRestRep)2