Search in sources :

Example 1 with ServiceImpl

use of com.emc.storageos.coordinator.common.impl.ServiceImpl 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 2 with ServiceImpl

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

the class CoordinatorClientImpl method locateAllServices.

@Override
public List<Service> locateAllServices(String siteId, String name, String version, String tag, String endpointKey) throws CoordinatorException {
    String serviceRoot = String.format("%1$s/%2$s", name, version);
    List<String> servicePaths = lookupServicePath(siteId, serviceRoot);
    if (servicePaths.isEmpty()) {
        throw CoordinatorException.retryables.cannotLocateService(String.format("%1$s/%2$s", getServicePath(siteId), serviceRoot));
    }
    // poor man's load balancing
    Collections.shuffle(servicePaths);
    List<Service> filtered = new ArrayList<Service>(servicePaths.size());
    for (int i = 0; i < servicePaths.size(); i++) {
        String spath = servicePaths.get(i);
        byte[] data = getServiceData(siteId, serviceRoot, spath);
        if (data == null) {
            continue;
        }
        Service service = ServiceImpl.parse(data);
        if (tag != null && !service.isTagged(tag)) {
            continue;
        }
        if (endpointKey != null && service.getEndpoint(endpointKey) == null) {
            continue;
        }
        if (endpointKey == null) {
            // default endpoint
            URI endpoint = expandEndpointURI(service.getEndpoint(), siteId);
            ((ServiceImpl) service).setEndpoint(endpoint);
        } else {
            // swap the ip for the entry with the endpointkey in the map
            URI endpoint = expandEndpointURI(service.getEndpoint(endpointKey), siteId);
            ((ServiceImpl) service).setEndpoint(endpointKey, endpoint);
        }
        log.debug("locateAllServices->service endpoint: " + service.getEndpoint());
        filtered.add(service);
    }
    return Collections.unmodifiableList(filtered);
}
Also used : ServiceImpl(com.emc.storageos.coordinator.common.impl.ServiceImpl) ArrayList(java.util.ArrayList) Service(com.emc.storageos.coordinator.common.Service) ExecutorService(java.util.concurrent.ExecutorService) PropertyInfoMapper.decodeFromString(com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString) URI(java.net.URI)

Example 3 with ServiceImpl

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

the class TestDbService method start.

/**
 * Starts the Cassandra DB, using any Persisted data files
 */
public void start() throws Exception {
    if (dbsvc != null) {
        return;
    }
    DataObjectScanner dataObjectScanner = new DataObjectScanner();
    dataObjectScanner.setPackages(modelPackages.toArray(new String[0]));
    dataObjectScanner.init();
    ServiceImpl dummyDBService = new ServiceImpl();
    dummyDBService.setName("dbsvc");
    dummyDBService.setVersion("1");
    dummyDBService.setEndpoint(URI.create("thrift://localhost:9170"));
    dummyDBService.setId("foobar");
    SchemaUtil schemaUtil = new SchemaUtil();
    schemaUtil.setKeyspaceName("Testing");
    schemaUtil.setService(dummyDBService);
    schemaUtil.setCoordinator(coordinatorClient);
    schemaUtil.setDataObjectScanner(dataObjectScanner);
    String config = createConfig(dataDir.getAbsolutePath());
    dbsvc = new DbServiceImpl();
    dbsvc.setConfig(config);
    dbsvc.setSchemaUtil(schemaUtil);
    dbsvc.setCoordinator(coordinatorClient);
    dbsvc.setService(dummyDBService);
    dbsvc.start();
}
Also used : DataObjectScanner(com.emc.storageos.db.common.DataObjectScanner) DbServiceImpl(com.emc.storageos.db.server.impl.DbServiceImpl) ServiceImpl(com.emc.storageos.coordinator.common.impl.ServiceImpl) DbServiceImpl(com.emc.storageos.db.server.impl.DbServiceImpl) SchemaUtil(com.emc.storageos.db.server.impl.SchemaUtil)

Example 4 with ServiceImpl

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

the class LocalCassandraService method startDb.

private void startDb() throws IOException {
    ServiceImpl service = new ServiceImpl();
    service.setName("dbsvc");
    service.setEndpoint(URI.create("thrift://localhost:9160"));
    service.setId("foobar");
    DataObjectScanner scanner = new DataObjectScanner();
    scanner.setPackages("com.emc.sa.model");
    scanner.init();
    SchemaUtil util = new SchemaUtil();
    util.setKeyspaceName(DEFAULT_KEYSPACE_NAME);
    util.setClusterName(DEFAULT_CLUSTER_NAME);
    util.setDataObjectScanner(scanner);
    util.setService(service);
    dbService = new DbServiceImpl();
    dbService.setConfig(createConfig(configResource, rootDir.getAbsolutePath()));
    dbService.setSchemaUtil(util);
    dbService.setCoordinator(coordinator);
    dbService.setService(service);
    dbService.start();
}
Also used : DataObjectScanner(com.emc.storageos.db.common.DataObjectScanner) DbServiceImpl(com.emc.storageos.db.server.impl.DbServiceImpl) ServiceImpl(com.emc.storageos.coordinator.common.impl.ServiceImpl) DbServiceImpl(com.emc.storageos.db.server.impl.DbServiceImpl) SchemaUtil(com.emc.storageos.db.server.impl.SchemaUtil)

Example 5 with ServiceImpl

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

the class TestSysServiceBeacon method testBeacon.

@Test
@Ignore("This references a configuration that doesn't exist (syssvc-config.xml), either fix or delete this test")
public void testBeacon() throws Exception {
    String curVersion = "current_version";
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("/syssvc-config.xml");
    SysSvcImpl sysservice = (SysSvcImpl) ctx.getBean(SERVICE_BEAN);
    sysservice.start();
    ServiceImpl svc = (ServiceImpl) ctx.getBean(SERVICE_INFO);
    CoordinatorClient client = connectClient();
    SysSvcBeaconImpl beacon = (SysSvcBeaconImpl) ctx.getBean(BEACON_BEAN);
    List<Service> found = client.locateAllServices(svc.getName(), svc.getVersion(), (String) null, null);
    Assert.assertNotNull(found);
    Assert.assertEquals(found.size(), 1);
    Service first = found.get(0);
    Assert.assertEquals(first.getId(), svc.getId());
    Assert.assertEquals(first.getEndpoint(), svc.getEndpoint());
    Assert.assertEquals(first.getAttribute(curVersion), null);
    svc.setAttribute(curVersion, "2");
    beacon.publish();
    found = client.locateAllServices(svc.getName(), svc.getVersion(), (String) null, null);
    Assert.assertNotNull(found);
    Assert.assertEquals(found.size(), 1);
    first = found.get(0);
    Assert.assertEquals(first.getId(), svc.getId());
    Assert.assertEquals(first.getEndpoint(), svc.getEndpoint());
    Assert.assertEquals(first.getAttribute(curVersion), "2");
    sysservice.stop();
}
Also used : SysSvcBeaconImpl(com.emc.storageos.systemservices.impl.SysSvcBeaconImpl) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SysSvcImpl(com.emc.storageos.systemservices.impl.SysSvcImpl) ServiceImpl(com.emc.storageos.coordinator.common.impl.ServiceImpl) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) Service(com.emc.storageos.coordinator.common.Service) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ServiceImpl (com.emc.storageos.coordinator.common.impl.ServiceImpl)6 DataObjectScanner (com.emc.storageos.db.common.DataObjectScanner)4 DbServiceImpl (com.emc.storageos.db.server.impl.DbServiceImpl)3 SchemaUtil (com.emc.storageos.db.server.impl.SchemaUtil)3 ArrayList (java.util.ArrayList)3 DbVersionInfo (com.emc.storageos.coordinator.client.model.DbVersionInfo)2 CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)2 Service (com.emc.storageos.coordinator.common.Service)2 DbServiceStatusChecker (com.emc.storageos.db.common.DbServiceStatusChecker)2 StubBeaconImpl (com.emc.storageos.db.server.util.StubBeaconImpl)2 PasswordUtils (com.emc.storageos.security.password.PasswordUtils)2 JmxServerWrapper (com.emc.storageos.services.util.JmxServerWrapper)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)1 DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)1 DualInetAddress (com.emc.storageos.coordinator.client.service.impl.DualInetAddress)1 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)1 PropertyInfoMapper.decodeFromString (com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)1 DbClientContext (com.emc.storageos.db.client.impl.DbClientContext)1 EncryptionProviderImpl (com.emc.storageos.db.client.impl.EncryptionProviderImpl)1