Search in sources :

Example 1 with AsterixEventServiceClient

use of org.apache.asterix.event.management.AsterixEventServiceClient 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 AsterixEventServiceClient

use of org.apache.asterix.event.management.AsterixEventServiceClient 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)

Example 3 with AsterixEventServiceClient

use of org.apache.asterix.event.management.AsterixEventServiceClient in project asterixdb by apache.

the class UninstallConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    UninstallConfig uninstallConfig = ((UninstallConfig) config);
    String instanceName = uninstallConfig.name;
    AsterixEventServiceUtil.validateAsterixInstanceExists(instanceName, State.INACTIVE);
    ILookupService lookupService = ServiceProvider.INSTANCE.getLookupService();
    AsterixInstance instance = lookupService.getAsterixInstance(instanceName);
    PatternCreator pc = PatternCreator.INSTANCE;
    Patterns patterns = pc.getLibraryUninstallPattern(instance, uninstallConfig.dataverseName, uninstallConfig.libraryName);
    AsterixEventServiceClient client = AsterixEventService.getAsterixEventServiceClient(instance.getCluster());
    client.submit(patterns);
    LOGGER.info("Uninstalled library " + uninstallConfig.libraryName);
}
Also used : AsterixEventServiceClient(org.apache.asterix.event.management.AsterixEventServiceClient) PatternCreator(org.apache.asterix.event.util.PatternCreator) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) Patterns(org.apache.asterix.event.schema.pattern.Patterns) ILookupService(org.apache.asterix.event.service.ILookupService)

Example 4 with AsterixEventServiceClient

use of org.apache.asterix.event.management.AsterixEventServiceClient in project asterixdb by apache.

the class StartNodeConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    String asterixInstanceName = ((StartNodeConfig) config).name;
    AsterixInstance instance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE, State.ACTIVE, State.UNUSABLE);
    Cluster cluster = instance.getCluster();
    List<Pattern> pl = new ArrayList<Pattern>();
    AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(instance);
    String[] nodesToBeAdded = ((StartNodeConfig) config).nodes.split(",");
    List<String> aliveNodes = new ArrayList<String>();
    for (ProcessInfo p : runtimeState.getProcesses()) {
        aliveNodes.add(p.getNodeId());
    }
    List<Node> clusterNodes = cluster.getNode();
    for (String n : nodesToBeAdded) {
        if (aliveNodes.contains(n)) {
            throw new InstallerException("Node: " + n + " is already alive");
        }
        for (Node node : clusterNodes) {
            if (n.equals(node.getId())) {
                String iodevices = node.getIodevices() == null ? cluster.getIodevices() : node.getIodevices();
                Pattern createNC = PatternCreator.INSTANCE.createNCStartPattern(cluster.getMasterNode().getClusterIp(), node.getId(), asterixInstanceName + "_" + node.getId(), iodevices, false);
                pl.add(createNC);
                break;
            }
        }
    }
    Patterns patterns = new Patterns(pl);
    AsterixEventServiceClient client = AsterixEventService.getAsterixEventServiceClient(cluster);
    client.submit(patterns);
    runtimeState = VerificationUtil.getAsterixRuntimeState(instance);
    VerificationUtil.updateInstanceWithRuntimeDescription(instance, runtimeState, true);
    LOGGER.info(instance.getDescription(false));
    ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
}
Also used : Pattern(org.apache.asterix.event.schema.pattern.Pattern) Node(org.apache.asterix.event.schema.cluster.Node) ArrayList(java.util.ArrayList) Cluster(org.apache.asterix.event.schema.cluster.Cluster) ProcessInfo(org.apache.asterix.event.model.ProcessInfo) AsterixEventServiceClient(org.apache.asterix.event.management.AsterixEventServiceClient) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) InstallerException(org.apache.asterix.installer.error.InstallerException) AsterixRuntimeState(org.apache.asterix.event.model.AsterixRuntimeState) Patterns(org.apache.asterix.event.schema.pattern.Patterns)

Example 5 with AsterixEventServiceClient

use of org.apache.asterix.event.management.AsterixEventServiceClient in project asterixdb by apache.

the class StopConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    String asterixInstanceName = ((StopConfig) config).name;
    AsterixInstance asterixInstance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.ACTIVE, State.UNUSABLE);
    AsterixEventServiceClient client = AsterixEventService.getAsterixEventServiceClient(asterixInstance.getCluster());
    List<Pattern> ncKillPatterns = new ArrayList<Pattern>();
    for (Node node : asterixInstance.getCluster().getNode()) {
        ncKillPatterns.add(PatternCreator.INSTANCE.createNCStopPattern(node.getId(), asterixInstanceName + "_" + node.getId()));
    }
    List<Pattern> ccKillPatterns = new ArrayList<Pattern>();
    ccKillPatterns.add(PatternCreator.INSTANCE.createCCStopPattern(asterixInstance.getCluster().getMasterNode().getId()));
    try {
        client.submit(new Patterns(ncKillPatterns));
        client.submit(new Patterns(ccKillPatterns));
    } catch (Exception e) {
        // processes are already dead
        LOGGER.debug("Attempt to kill non-existing processess");
    }
    asterixInstance.setState(State.INACTIVE);
    asterixInstance.setStateChangeTimestamp(new Date());
    ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(asterixInstance);
    LOGGER.info("Stopped Asterix instance: " + asterixInstanceName);
}
Also used : Pattern(org.apache.asterix.event.schema.pattern.Pattern) AsterixEventServiceClient(org.apache.asterix.event.management.AsterixEventServiceClient) Node(org.apache.asterix.event.schema.cluster.Node) ArrayList(java.util.ArrayList) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) Patterns(org.apache.asterix.event.schema.pattern.Patterns) Date(java.util.Date)

Aggregations

AsterixEventServiceClient (org.apache.asterix.event.management.AsterixEventServiceClient)7 AsterixInstance (org.apache.asterix.event.model.AsterixInstance)7 Patterns (org.apache.asterix.event.schema.pattern.Patterns)7 AsterixRuntimeState (org.apache.asterix.event.model.AsterixRuntimeState)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 Node (org.apache.asterix.event.schema.cluster.Node)3 Pattern (org.apache.asterix.event.schema.pattern.Pattern)3 InstallerException (org.apache.asterix.installer.error.InstallerException)3 ClusterState (org.apache.asterix.common.api.IClusterManagementWork.ClusterState)2 ProcessInfo (org.apache.asterix.event.model.ProcessInfo)2 ClusterStateWatcher (org.apache.asterix.event.service.ClusterStateWatcher)2 PatternCreator (org.apache.asterix.event.util.PatternCreator)2 File (java.io.File)1 FilenameFilter (java.io.FilenameFilter)1 Cluster (org.apache.asterix.event.schema.cluster.Cluster)1 ILookupService (org.apache.asterix.event.service.ILookupService)1