Search in sources :

Example 1 with CoordinatorClientInetAddressMap

use of com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap in project coprhd-controller by CoprHD.

the class DisasterRecoveryServiceTest method testPrecheckForFailover_Error.

@Test
public void testPrecheckForFailover_Error() {
    // API should be only send to local site
    try {
        doReturn(standbySite2).when(drUtil).getLocalSite();
        drService.precheckForFailover();
        fail();
    } catch (InternalServerErrorException e) {
    // ignore
    }
    // should be synced
    try {
        doReturn(standbySite1).when(drUtil).getLocalSite();
        standbySite1.setState(SiteState.STANDBY_ERROR);
        drService.precheckForFailover();
        fail();
    } catch (InternalServerErrorException e) {
    // ignore
    }
    // show be only standby
    try {
        standbySite1.setState(SiteState.STANDBY_SYNCED);
        doReturn(true).when(drUtil).isActiveSite();
        drService.precheckForFailover();
        fail();
    } catch (InternalServerErrorException | BadRequestException e) {
    // ignore
    }
    // should be stable
    try {
        doReturn(false).when(drUtil).isActiveSite();
        doReturn(ClusterInfo.ClusterState.DEGRADED).when(coordinator).getControlNodesState(standbySite1.getUuid());
        drService.precheckForFailover();
        fail();
    } catch (InternalServerErrorException e) {
    // ignore
    }
    // ZK should not be observer or read-only
    try {
        CoordinatorClientInetAddressMap addrLookupMap = new CoordinatorClientInetAddressMap();
        addrLookupMap.setNodeId("vipr1");
        doReturn(addrLookupMap).when(coordinator).getInetAddessLookupMap();
        doReturn(ClusterInfo.ClusterState.STABLE).when(coordinator).getControlNodesState(standbySite1.getUuid());
        doReturn("observer").when(drUtil).getLocalCoordinatorMode();
        drService.precheckForFailover();
        fail();
    } catch (InternalServerErrorException e) {
    // ignore
    }
}
Also used : CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Test(org.junit.Test)

Example 2 with CoordinatorClientInetAddressMap

use of com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap in project coprhd-controller by CoprHD.

the class TestDBClientUtils method newDBClient.

public static DbClientImpl newDBClient() throws Exception {
    ZkConnection zkConnection = new ZkConnection();
    zkConnection.setServer(Lists.newArrayList(new URI("coordinator://localhost:2181")));
    zkConnection.build();
    DualInetAddress dualInetAddress = DualInetAddress.fromAddresses("127.0.0.1", "::1");
    Map<String, DualInetAddress> addresses = Maps.newHashMap();
    addresses.put("localhost", dualInetAddress);
    CoordinatorClientInetAddressMap map = new CoordinatorClientInetAddressMap();
    map.setNodeId("standalone");
    map.setDualInetAddress(dualInetAddress);
    map.setControllerNodeIPLookupMap(addresses);
    CoordinatorClientImpl coordinatorClient = new CoordinatorClientImpl();
    coordinatorClient.setZkConnection(zkConnection);
    coordinatorClient.setInetAddessLookupMap(map);
    coordinatorClient.start();
    DbClientContext localContext = new DbClientContext();
    localContext.setKeyspaceName("StorageOS");
    localContext.setClusterName("StorageOs");
    DbClientContext geoContext = new DbClientContext();
    geoContext.setKeyspaceName("GeoStorageOs");
    geoContext.setClusterName("GeoStorageOs");
    DbVersionInfo versionInfo = new DbVersionInfo();
    versionInfo.setSchemaVersion("2.0");
    DbClientImpl client = new DbClientImpl();
    client.setDbVersionInfo(versionInfo);
    client.setLocalContext(localContext);
    client.setGeoContext(geoContext);
    client.setCoordinatorClient(coordinatorClient);
    client.setLocalContext(new DbClientContext());
    client.start();
    VdcUtil.setDbClient(client);
    return client;
}
Also used : CoordinatorClientImpl(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl) DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress) DbVersionInfo(com.emc.storageos.coordinator.client.model.DbVersionInfo)

Example 3 with CoordinatorClientInetAddressMap

use of com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap in project coprhd-controller by CoprHD.

the class DbsvcTestBase method startDb.

/**
 * Start embedded DB
 */
protected static void startDb(String currentVersion, String targetVersion, String extraModelsPkg, DataObjectScanner scanner, boolean createMockHandler) throws IOException {
    sourceVersion = new DbVersionInfo();
    sourceVersion.setSchemaVersion(currentVersion);
    DbVersionInfo targetVersionInfo = new DbVersionInfo();
    targetVersionInfo.setSchemaVersion(targetVersion);
    List<String> packages = new ArrayList<String>();
    packages.add("com.emc.storageos.db.client.model");
    packages.add("com.emc.sa.model");
    if (extraModelsPkg != null) {
        packages.add(extraModelsPkg);
    }
    String[] pkgsArray = packages.toArray(new String[packages.size()]);
    service = new ServiceImpl();
    service.setName("dbsvc");
    service.setVersion(targetVersion);
    service.setEndpoint(URI.create("thrift://localhost:9160"));
    service.setId("db-standalone");
    StubBeaconImpl beacon = new StubBeaconImpl(service);
    if (scanner == null) {
        scanner = new DataObjectScanner();
        scanner.setPackages(pkgsArray);
        scanner.init();
    }
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("nodeaddrmap-var.xml");
    CoordinatorClientInetAddressMap inetAddressMap = (CoordinatorClientInetAddressMap) ctx.getBean("inetAddessLookupMap");
    if (inetAddressMap == null) {
        _log.error("CoordinatorClientInetAddressMap is not initialized. Node address lookup will fail.");
    }
    _coordinator.setInetAddessLookupMap(inetAddressMap);
    _coordinator.setDbVersionInfo(sourceVersion);
    ConfigurationImpl cfg = new ConfigurationImpl();
    cfg.setKind(Constants.DB_CONFIG);
    cfg.setId(Constants.GLOBAL_ID);
    cfg.setConfig(Constants.SCHEMA_VERSION, currentVersion);
    _coordinator.persistServiceConfiguration(cfg);
    statusChecker = new DbServiceStatusChecker();
    statusChecker.setCoordinator(_coordinator);
    statusChecker.setClusterNodeCount(1);
    statusChecker.setDbVersionInfo(sourceVersion);
    statusChecker.setServiceName(service.getName());
    SecretKey key = null;
    try {
        KeyGenerator keyGenerator = null;
        keyGenerator = KeyGenerator.getInstance("HmacSHA256");
        key = keyGenerator.generateKey();
    } catch (NoSuchAlgorithmException e) {
        fail("generate key fail");
    }
    schemaUtil = new MockSchemaUtil();
    schemaUtil.setKeyspaceName("Test");
    schemaUtil.setClusterName("Test");
    schemaUtil.setDataObjectScanner(scanner);
    schemaUtil.setService(service);
    schemaUtil.setStatusChecker(statusChecker);
    schemaUtil.setCoordinator(_coordinator);
    schemaUtil.setVdcShortId("datacenter1");
    schemaUtil.setDrUtil(new DrUtil(_coordinator));
    DbClientContext dbctx = new MockDbClientContext();
    dbctx.setClusterName("Test");
    dbctx.setKeyspaceName("Test");
    schemaUtil.setClientContext(dbctx);
    Properties props = new Properties();
    props.put(DbClientImpl.DB_STAT_OPTIMIZE_DISK_SPACE, "false");
    schemaUtil.setDbCommonInfo(props);
    List<String> vdcHosts = new ArrayList();
    vdcHosts.add("127.0.0.1");
    schemaUtil.setVdcNodeList(vdcHosts);
    schemaUtil.setDbCommonInfo(new java.util.Properties());
    JmxServerWrapper jmx = new JmxServerWrapper();
    if (_startJmx) {
        jmx.setEnabled(true);
        jmx.setServiceUrl("service:jmx:rmi://localhost:%d/jndi/rmi://%s:%d/jmxrmi");
        jmx.setHost("127.0.0.1");
        jmx.setPort(7199);
        jmx.setExportPort(7200);
    } else {
        jmx.setEnabled(false);
    }
    _encryptionProvider.setCoordinator(_coordinator);
    _dbClient = getDbClientBase();
    _dbClient.setDbVersionInfo(targetVersionInfo);
    PasswordUtils passwordUtils = new PasswordUtils();
    passwordUtils.setCoordinator(_coordinator);
    passwordUtils.setEncryptionProvider(_encryptionProvider);
    passwordUtils.setDbClient(_dbClient);
    schemaUtil.setPasswordUtils(passwordUtils);
    DependencyChecker localDependencyChecker = new DependencyChecker(_dbClient, scanner);
    _geoDependencyChecker = new GeoDependencyChecker(_dbClient, _coordinator, localDependencyChecker);
    _dbsvc = new TestMockDbServiceImpl();
    _dbsvc.setConfig("db-test.yaml");
    _dbsvc.setSchemaUtil(schemaUtil);
    _dbsvc.setCoordinator(_coordinator);
    _dbsvc.setStatusChecker(statusChecker);
    _dbsvc.setService(service);
    _dbsvc.setJmxServerWrapper(jmx);
    _dbsvc.setDbClient(_dbClient);
    _dbsvc.setBeacon(beacon);
    _dbsvc.setDbDir(dataDir);
    _dbsvc.setDisableScheduledDbRepair(true);
    _dbsvc.setMigrationHandler(getMigrationHandler(createMockHandler, pkgsArray));
    _dbsvc.setDbMgr(new MockDbManager());
    _dbsvc.start();
    isDbStarted = true;
}
Also used : DataObjectScanner(com.emc.storageos.db.common.DataObjectScanner) ArrayList(java.util.ArrayList) PasswordUtils(com.emc.storageos.security.password.PasswordUtils) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DependencyChecker(com.emc.storageos.db.common.DependencyChecker) GeoDependencyChecker(com.emc.storageos.security.geo.GeoDependencyChecker) Properties(java.util.Properties) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) StubBeaconImpl(com.emc.storageos.db.server.util.StubBeaconImpl) ConfigurationImpl(com.emc.storageos.coordinator.common.impl.ConfigurationImpl) KeyGenerator(javax.crypto.KeyGenerator) Properties(java.util.Properties) GeoDependencyChecker(com.emc.storageos.security.geo.GeoDependencyChecker) ServiceImpl(com.emc.storageos.coordinator.common.impl.ServiceImpl) DbServiceImpl(com.emc.storageos.db.server.impl.DbServiceImpl) DbServiceStatusChecker(com.emc.storageos.db.common.DbServiceStatusChecker) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil) DbVersionInfo(com.emc.storageos.coordinator.client.model.DbVersionInfo) SecretKey(javax.crypto.SecretKey) DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) JmxServerWrapper(com.emc.storageos.services.util.JmxServerWrapper)

Example 4 with CoordinatorClientInetAddressMap

use of com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap in project coprhd-controller by CoprHD.

the class KeyCertificatePairGeneratorTest method setup.

@Before
public void setup() throws IOException, URISyntaxException {
    ApplicationContextUtil.initContext(System.getProperty("buildType"), ApplicationContextUtil.SECURITY_CONTEXTS);
    List<URI> uri = new ArrayList<URI>();
    uri.add(URI.create(coordinatorServer));
    ZkConnection connection = new ZkConnection();
    connection.setServer(uri);
    connection.build();
    coordinatorClient.setZkConnection(connection);
    CoordinatorClientInetAddressMap map = new CoordinatorClientInetAddressMap();
    map.setNodeId("standalone");
    DualInetAddress localAddress = DualInetAddress.fromAddresses("127.0.0.1", "::1");
    map.setDualInetAddress(localAddress);
    Map<String, DualInetAddress> controllerNodeIPLookupMap = new HashMap<String, DualInetAddress>();
    controllerNodeIPLookupMap.put("localhost", localAddress);
    map.setControllerNodeIPLookupMap(controllerNodeIPLookupMap);
    coordinatorClient.setInetAddessLookupMap(map);
    coordinatorClient.start();
    FileInputStream is = new FileInputStream(defaultOvfPropsLocation);
    Properties defaultProp = new Properties();
    defaultProp.load(is);
    is.close();
    is = new FileInputStream(ovfPropsLocation);
    Properties ovfProps = new Properties();
    ovfProps.load(is);
    is.close();
    CoordinatorClientImpl.setDefaultProperties(defaultProp);
    CoordinatorClientImpl.setOvfProperties(ovfProps);
    defaultValues = new KeyCertificateAlgorithmValuesHolder(coordinatorClient);
    String envVar = System.getenv(LOCALHOST_IP);
    if (StringUtils.isNotBlank(envVar)) {
        localhostIP = envVar;
    }
    InetAddress localhost = InetAddress.getByName(localhostIP);
    localhostName = localhost.getCanonicalHostName();
}
Also used : URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) FileInputStream(java.io.FileInputStream) KeyCertificateAlgorithmValuesHolder(com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) InetAddress(java.net.InetAddress) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress) Before(org.junit.Before)

Example 5 with CoordinatorClientInetAddressMap

use of com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap in project coprhd-controller by CoprHD.

the class KeystoreTest method setup.

@Before
public void setup() throws URISyntaxException, IOException {
    ApplicationContextUtil.initContext(System.getProperty("buildType"), ApplicationContextUtil.SECURITY_CONTEXTS);
    List<URI> uri = new ArrayList<URI>();
    uri.add(URI.create(coordinatorServer));
    ZkConnection connection = new ZkConnection();
    connection.setServer(uri);
    connection.build();
    coordinatorClient.setZkConnection(connection);
    CoordinatorClientInetAddressMap map = new CoordinatorClientInetAddressMap();
    map.setNodeId("standalone");
    DualInetAddress localAddress = DualInetAddress.fromAddresses("127.0.0.1", "::1");
    map.setDualInetAddress(localAddress);
    Map<String, DualInetAddress> controllerNodeIPLookupMap = new HashMap<String, DualInetAddress>();
    controllerNodeIPLookupMap.put("localhost", localAddress);
    map.setControllerNodeIPLookupMap(controllerNodeIPLookupMap);
    coordinatorClient.setInetAddessLookupMap(map);
    coordinatorClient.start();
    FileInputStream is = new FileInputStream(defaultOvfPropsLocation);
    Properties defaultProp = new Properties();
    defaultProp.load(is);
    is.close();
    is = new FileInputStream(ovfPropsLocation);
    Properties ovfProps = new Properties();
    ovfProps.load(is);
    is.close();
    CoordinatorClientImpl.setDefaultProperties(defaultProp);
    CoordinatorClientImpl.setOvfProperties(ovfProps);
    loadStoreParam = new DistributedLoadKeyStoreParam();
    loadStoreParam.setCoordinator(coordinatorClient);
    invalidLoadStoreParam = new LoadStoreParameter() {

        @Override
        public ProtectionParameter getProtectionParameter() {
            return null;
        }
    };
    gen = new KeyCertificatePairGenerator();
    KeyCertificateAlgorithmValuesHolder values = new KeyCertificateAlgorithmValuesHolder(coordinatorClient);
    gen.setKeyCertificateAlgorithmValuesHolder(values);
}
Also used : HashMap(java.util.HashMap) DistributedLoadKeyStoreParam(com.emc.storageos.security.keystore.impl.DistributedLoadKeyStoreParam) ArrayList(java.util.ArrayList) Properties(java.util.Properties) URI(java.net.URI) ZkConnection(com.emc.storageos.coordinator.common.impl.ZkConnection) FileInputStream(java.io.FileInputStream) LoadStoreParameter(java.security.KeyStore.LoadStoreParameter) KeyCertificateAlgorithmValuesHolder(com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder) KeyCertificatePairGenerator(com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator) CoordinatorClientInetAddressMap(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap) DualInetAddress(com.emc.storageos.coordinator.client.service.impl.DualInetAddress) ProtectionParameter(java.security.KeyStore.ProtectionParameter) Before(org.junit.Before)

Aggregations

CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)22 DualInetAddress (com.emc.storageos.coordinator.client.service.impl.DualInetAddress)13 ZkConnection (com.emc.storageos.coordinator.common.impl.ZkConnection)9 ArrayList (java.util.ArrayList)9 URI (java.net.URI)8 HashMap (java.util.HashMap)7 FileInputStream (java.io.FileInputStream)6 CoordinatorClientImpl (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl)5 Properties (java.util.Properties)5 Before (org.junit.Before)5 DbVersionInfo (com.emc.storageos.coordinator.client.model.DbVersionInfo)4 KeyCertificateAlgorithmValuesHolder (com.emc.storageos.security.keystore.impl.KeyCertificateAlgorithmValuesHolder)4 KeyCertificatePairGenerator (com.emc.storageos.security.keystore.impl.KeyCertificatePairGenerator)3 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)2 Configuration (com.emc.storageos.coordinator.common.Configuration)2 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)2 ServiceImpl (com.emc.storageos.coordinator.common.impl.ServiceImpl)2 DbClientContext (com.emc.storageos.db.client.impl.DbClientContext)2 DbClientImpl (com.emc.storageos.db.client.impl.DbClientImpl)2