Search in sources :

Example 1 with ClusterStateWatcher

use of org.apache.asterix.event.service.ClusterStateWatcher in project asterixdb by apache.

the class StartConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    String asterixInstanceName = ((StartConfig) config).name;
    AsterixInstance instance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE);
    AsterixEventServiceUtil.createAsterixZip(instance);
    AsterixEventServiceClient client = AsterixEventService.getAsterixEventServiceClient(instance.getCluster());
    Patterns asterixBinaryTransferPattern = PatternCreator.INSTANCE.getAsterixBinaryTransferPattern(asterixInstanceName, instance.getCluster());
    client.submit(asterixBinaryTransferPattern);
    // Start the watcher
    ClusterStateWatcher stateWatcher = ServiceProvider.INSTANCE.getLookupService().startWatchingClusterState(asterixInstanceName);
    AsterixEventServiceUtil.createClusterProperties(instance.getCluster(), instance.getAsterixConfiguration());
    Patterns patterns = PatternCreator.INSTANCE.getStartAsterixPattern(asterixInstanceName, instance.getCluster(), false);
    client.submit(patterns);
    // Check the cluster state
    ClusterState clusterState = stateWatcher.waitForClusterStart();
    if (clusterState != ClusterState.ACTIVE) {
        throw new Exception("CC failed to start");
    }
    AsterixEventServiceUtil.deleteDirectory(InstallerDriver.getManagixHome() + File.separator + InstallerDriver.ASTERIX_DIR + File.separator + asterixInstanceName);
    AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(instance);
    VerificationUtil.updateInstanceWithRuntimeDescription(instance, runtimeState, true);
    LOGGER.info(instance.getDescription(false));
    ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
}
Also used : ClusterState(org.apache.asterix.common.api.IClusterManagementWork.ClusterState) AsterixEventServiceClient(org.apache.asterix.event.management.AsterixEventServiceClient) ClusterStateWatcher(org.apache.asterix.event.service.ClusterStateWatcher) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) Patterns(org.apache.asterix.event.schema.pattern.Patterns) AsterixRuntimeState(org.apache.asterix.event.model.AsterixRuntimeState)

Example 2 with ClusterStateWatcher

use of org.apache.asterix.event.service.ClusterStateWatcher in project asterixdb by apache.

the class CreateConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    ValidateCommand validateCommand = new ValidateCommand();
    boolean valid = validateCommand.validateCluster(((CreateConfig) config).clusterPath);
    if (!valid) {
        throw new Exception("Cannot create an Asterix instance.");
    }
    asterixInstanceName = ((CreateConfig) config).name;
    AsterixEventServiceUtil.validateAsterixInstanceNotExists(asterixInstanceName);
    CreateConfig createConfig = (CreateConfig) config;
    cluster = EventUtil.getCluster(createConfig.clusterPath);
    cluster.setInstanceName(asterixInstanceName);
    asterixConfiguration = InstallerUtil.getAsterixConfiguration(createConfig.asterixConfPath);
    AsterixInstance asterixInstance = AsterixEventServiceUtil.createAsterixInstance(asterixInstanceName, cluster, asterixConfiguration);
    AsterixEventServiceUtil.evaluateConflictWithOtherInstances(asterixInstance);
    AsterixEventServiceUtil.createAsterixZip(asterixInstance);
    AsterixEventServiceUtil.createClusterProperties(cluster, asterixConfiguration);
    AsterixEventServiceClient eventrixClient = AsterixEventService.getAsterixEventServiceClient(cluster, true, false);
    // Store the cluster initially in Zookeeper and start watching
    ServiceProvider.INSTANCE.getLookupService().writeAsterixInstance(asterixInstance);
    ClusterStateWatcher stateWatcher = ServiceProvider.INSTANCE.getLookupService().startWatchingClusterState(asterixInstanceName);
    Patterns asterixBinarytrasnferPattern = PatternCreator.INSTANCE.getAsterixBinaryTransferPattern(asterixInstanceName, cluster);
    eventrixClient.submit(asterixBinarytrasnferPattern);
    Patterns patterns = PatternCreator.INSTANCE.getStartAsterixPattern(asterixInstanceName, cluster, true);
    eventrixClient.submit(patterns);
    // Check the cluster state
    ClusterState clusterState = stateWatcher.waitForClusterStart();
    if (clusterState != ClusterState.ACTIVE) {
        throw new Exception("CC failed to start");
    }
    AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(asterixInstance);
    VerificationUtil.updateInstanceWithRuntimeDescription(asterixInstance, runtimeState, true);
    ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(asterixInstance);
    AsterixEventServiceUtil.deleteDirectory(InstallerDriver.getManagixHome() + File.separator + InstallerDriver.ASTERIX_DIR + File.separator + asterixInstanceName);
    LOGGER.info(asterixInstance.getDescription(false));
}
Also used : ClusterState(org.apache.asterix.common.api.IClusterManagementWork.ClusterState) AsterixEventServiceClient(org.apache.asterix.event.management.AsterixEventServiceClient) ClusterStateWatcher(org.apache.asterix.event.service.ClusterStateWatcher) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) Patterns(org.apache.asterix.event.schema.pattern.Patterns) AsterixRuntimeState(org.apache.asterix.event.model.AsterixRuntimeState)

Aggregations

ClusterState (org.apache.asterix.common.api.IClusterManagementWork.ClusterState)2 AsterixEventServiceClient (org.apache.asterix.event.management.AsterixEventServiceClient)2 AsterixInstance (org.apache.asterix.event.model.AsterixInstance)2 AsterixRuntimeState (org.apache.asterix.event.model.AsterixRuntimeState)2 Patterns (org.apache.asterix.event.schema.pattern.Patterns)2 ClusterStateWatcher (org.apache.asterix.event.service.ClusterStateWatcher)2