Search in sources :

Example 1 with DrUtil

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

the class DbRebuildRunnable method run.

@Override
public void run() {
    if (isRunning) {
        log.info("db rebuild in progress, nothing to do");
        return;
    }
    DrUtil drUtil = new DrUtil(coordinator);
    Site localSite = drUtil.getLocalSite();
    if (!localSite.getState().equals(SiteState.STANDBY_SYNCING)) {
        log.info("db in sync, nothing to do");
        return;
    }
    Configuration dbconfig = coordinator.queryConfiguration(coordinator.getSiteId(), coordinator.getVersionedDbConfigPath(service.getName(), service.getVersion()), service.getId());
    if (isLastDataSyncCurrent(dbconfig)) {
        log.info("last data sync time is later than the target site info update, nothing to do");
        return;
    }
    Site primarySite = drUtil.getActiveSite();
    String sourceDc = drUtil.getCassandraDcId(primarySite);
    log.info("starting db rebuild from source dc {}", sourceDc);
    isRunning = true;
    StorageService.instance.rebuild(sourceDc);
    long currentSyncTime = System.currentTimeMillis();
    log.info("local db rebuild finishes. Updating last data sync time to {}", currentSyncTime);
    dbconfig.setConfig(DbConfigConstants.LAST_DATA_SYNC_TIME, String.valueOf(currentSyncTime));
    coordinator.persistServiceConfiguration(coordinator.getSiteId(), dbconfig);
    if (dbRebuildComplete(Constants.DBSVC_NAME) && dbRebuildComplete(Constants.GEODBSVC_NAME)) {
        localSite = drUtil.getLocalSite();
        // do nothing if it gets set to STANDBY_ERROR earlier
        if (localSite.getState().equals(SiteState.STANDBY_SYNCING)) {
            purgeOldDataRevision(drUtil);
            // reset heartbeat for this site
            SiteMonitorResult dbHeartbeat = coordinator.getTargetInfo(localSite.getUuid(), SiteMonitorResult.class);
            if (dbHeartbeat != null) {
                dbHeartbeat.setDbQuorumLostSince(0);
                coordinator.setTargetInfo(localSite.getUuid(), dbHeartbeat);
                log.info("Reset db heartbeat state for {}", localSite.getUuid());
            }
            log.info("all db rebuild finish, updating site state to STANDBY_SYNCED");
            localSite.setState(SiteState.STANDBY_SYNCED);
            coordinator.persistServiceConfiguration(localSite.toConfiguration());
        }
    }
    isRunning = false;
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) Configuration(com.emc.storageos.coordinator.common.Configuration) SiteMonitorResult(com.emc.storageos.coordinator.client.model.SiteMonitorResult) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil)

Example 2 with DrUtil

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

the class DrInternodeAuthenticator method validateConfiguration.

/**
 * Called by Cassandra startup routine to initialize this instance
 */
@Override
public void validateConfiguration() throws ConfigurationException {
    log.info("Initializing DrInternodeAuthenticator");
    CoordinatorClient coordinatorClient = DbServiceImpl.instance.getCoordinator();
    DrUtil drUtil = new DrUtil(coordinatorClient);
    Site localSite = drUtil.getLocalSite();
    isStandbyDegraded = localSite.getState().equals(SiteState.STANDBY_DEGRADED) || localSite.getState().equals(SiteState.STANDBY_DEGRADING);
    isStandbyPaused = localSite.getState().equals(SiteState.STANDBY_PAUSING) || localSite.getState().equals(SiteState.STANDBY_PAUSED);
    isActiveDegraded = localSite.getState().equals(SiteState.ACTIVE_DEGRADED);
    Collection<String> nodeAddrList = localSite.getHostIPv4AddressMap().values();
    if (!localSite.isUsingIpv4()) {
        nodeAddrList = localSite.getHostIPv6AddressMap().values();
    }
    for (String nodeAddr : nodeAddrList) {
        try {
            localAddresses.add(InetAddress.getByName(nodeAddr));
        } catch (UnknownHostException e) {
            log.error("Invalid IP address {}", nodeAddr);
        }
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) UnknownHostException(java.net.UnknownHostException) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient)

Example 3 with DrUtil

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

the class DbClientTest method setupTest.

@Before
public void setupTest() {
    DbClientImplUnitTester dbClient = new DbClientImplUnitTester();
    dbClient.setCoordinatorClient(_coordinator);
    dbClient.setDbVersionInfo(sourceVersion);
    dbClient.setBypassMigrationLock(true);
    _encryptionProvider.setCoordinator(_coordinator);
    dbClient.setEncryptionProvider(_encryptionProvider);
    DbClientContext localCtx = new DbClientContext();
    localCtx.setClusterName("Test");
    localCtx.setKeyspaceName("Test");
    dbClient.setLocalContext(localCtx);
    VdcUtil.setDbClient(dbClient);
    dbClient.setBypassMigrationLock(false);
    dbClient.setDrUtil(new DrUtil(_coordinator));
    dbClient.start();
    _dbClient = dbClient;
}
Also used : DbClientContext(com.emc.storageos.db.client.impl.DbClientContext) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil) Before(org.junit.Before)

Example 4 with DrUtil

use of com.emc.storageos.coordinator.client.service.DrUtil 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 5 with DrUtil

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

the class CoordinatorImpl method startMutexReaper.

/**
 * Reaper mutex dirs generated from InterProcessMutex
 */
private void startMutexReaper() {
    Thread childReaperThread = new Thread(new Runnable() {

        public void run() {
            try {
                // from LoggingBean, needs to wait for CoordinatorSvc started.
                while (!_coordinatorClient.isConnected()) {
                    _log.info("Waiting for connection to cluster ...");
                    Thread.sleep(3 * 1000);
                }
                _log.info("Connected to cluster");
                DrUtil drUtil = new DrUtil(_coordinatorClient);
                if (drUtil.isStandby()) {
                    _log.info("Skip mutex reapter on standby site");
                    return;
                }
                /**
                 * Reaper empty dirs under /mutex in zookeeper
                 * It leverages curator Reaper and ChildReaper to remove empty sub dirs.
                 * It leverages LeaderSelector to assure only one reaper running at the same time.
                 * Note: Please use autoRequeue() to requeue for competing leader automatically
                 * while connection broken and reconnected. The requeue() has a bug in curator
                 * 1.3.4 and should not be used.
                 */
                LeaderSelectorListener listener = new ReaperLeaderSelectorListener(ZkPath.MUTEX.toString());
                String _leaderRelativePath = "mutexReaper";
                LeaderSelector leaderSel = _coordinatorClient.getLeaderSelector(_leaderRelativePath, listener);
                leaderSel.autoRequeue();
                leaderSel.start();
            } catch (Exception e) {
                _log.warn("reaper task threw", e);
            }
        }
    }, "reaper thread");
    childReaperThread.start();
}
Also used : ReaperLeaderSelectorListener(com.emc.storageos.coordinator.client.service.impl.ReaperLeaderSelectorListener) LeaderSelectorListener(org.apache.curator.framework.recipes.leader.LeaderSelectorListener) ReaperLeaderSelectorListener(com.emc.storageos.coordinator.client.service.impl.ReaperLeaderSelectorListener) DrUtil(com.emc.storageos.coordinator.client.service.DrUtil) LeaderSelector(org.apache.curator.framework.recipes.leader.LeaderSelector) IOException(java.io.IOException) JMException(javax.management.JMException)

Aggregations

DrUtil (com.emc.storageos.coordinator.client.service.DrUtil)26 Site (com.emc.storageos.coordinator.client.model.Site)11 DbClientContext (com.emc.storageos.db.client.impl.DbClientContext)4 SiteInfo (com.emc.storageos.coordinator.client.model.SiteInfo)3 CoordinatorClientInetAddressMap (com.emc.storageos.coordinator.client.service.impl.CoordinatorClientInetAddressMap)3 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)3 PropertyInfoMapper.decodeFromString (com.emc.storageos.coordinator.mapper.PropertyInfoMapper.decodeFromString)3 SiteState (com.emc.storageos.coordinator.client.model.SiteState)2 CoordinatorClient (com.emc.storageos.coordinator.client.service.CoordinatorClient)2 Configuration (com.emc.storageos.coordinator.common.Configuration)2 Service (com.emc.storageos.coordinator.common.Service)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 SysClientException (com.emc.storageos.systemservices.exceptions.SysClientException)2 ClusterInfo (com.emc.vipr.model.sys.ClusterInfo)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 SiteMapper (com.emc.storageos.api.mapper.SiteMapper)1 DbVersionInfo (com.emc.storageos.coordinator.client.model.DbVersionInfo)1 MigrationStatus (com.emc.storageos.coordinator.client.model.MigrationStatus)1