Search in sources :

Example 6 with AsterixRuntimeState

use of org.apache.asterix.event.model.AsterixRuntimeState in project asterixdb by apache.

the class AsterixInstallerIntegrationUtil method createInstance.

public static void createInstance() throws Exception {
    String command = null;
    AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(ASTERIX_INSTANCE_NAME);
    if (instance != null) {
        transformIntoRequiredState(State.INACTIVE);
        command = "delete -n " + ASTERIX_INSTANCE_NAME;
        cmdHandler.processCommand(command.split(" "));
    }
    command = "create -n " + ASTERIX_INSTANCE_NAME + " " + "-c" + " " + clusterConfigurationPath;
    cmdHandler.processCommand(command.split(" "));
    instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(ASTERIX_INSTANCE_NAME);
    AsterixRuntimeState state = VerificationUtil.getAsterixRuntimeState(instance);
    assert (state.getFailedNCs().isEmpty() && state.isCcRunning());
}
Also used : AsterixInstance(org.apache.asterix.event.model.AsterixInstance) AsterixRuntimeState(org.apache.asterix.event.model.AsterixRuntimeState)

Example 7 with AsterixRuntimeState

use of org.apache.asterix.event.model.AsterixRuntimeState 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 8 with AsterixRuntimeState

use of org.apache.asterix.event.model.AsterixRuntimeState in project asterixdb by apache.

the class StopNodeConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    String asterixInstanceName = ((StopNodeConfig) config).name;
    AsterixInstance asterixInstance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.ACTIVE, State.UNUSABLE);
    AsterixEventServiceClient client = AsterixEventService.getAsterixEventServiceClient(asterixInstance.getCluster());
    String[] nodesToStop = ((StopNodeConfig) config).nodeList.split(",");
    AsterixRuntimeState runtimeState = VerificationUtil.getAsterixRuntimeState(asterixInstance);
    List<String> aliveNodes = new ArrayList<String>();
    for (ProcessInfo p : runtimeState.getProcesses()) {
        aliveNodes.add(p.getNodeId());
    }
    List<String> validNodeIds = new ArrayList<String>();
    for (Node node : asterixInstance.getCluster().getNode()) {
        validNodeIds.add(node.getId());
    }
    List<Pattern> ncKillPatterns = new ArrayList<Pattern>();
    for (String nodeId : nodesToStop) {
        if (!nodeId.contains(nodeId)) {
            throw new InstallerException("Invalid nodeId: " + nodeId);
        }
        if (!aliveNodes.contains(nodeId)) {
            throw new InstallerException("Node: " + nodeId + " is not alive");
        }
        ncKillPatterns.add(PatternCreator.INSTANCE.createNCStopPattern(nodeId, asterixInstanceName + "_" + nodeId));
    }
    try {
        client.submit(new Patterns(ncKillPatterns));
    } catch (Exception e) {
        // processes are already dead
        LOGGER.debug("Attempt to kill non-existing processess");
    }
    asterixInstance.setStateChangeTimestamp(new Date());
    ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(asterixInstance);
    LOGGER.info("Stopped nodes " + ((StopNodeConfig) config).nodeList + " serving Asterix instance: " + asterixInstanceName);
}
Also used : Pattern(org.apache.asterix.event.schema.pattern.Pattern) Node(org.apache.asterix.event.schema.cluster.Node) ArrayList(java.util.ArrayList) ProcessInfo(org.apache.asterix.event.model.ProcessInfo) InstallerException(org.apache.asterix.installer.error.InstallerException) Date(java.util.Date) 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 9 with AsterixRuntimeState

use of org.apache.asterix.event.model.AsterixRuntimeState in project asterixdb by apache.

the class DescribeConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    String asterixInstanceName = ((DescribeConfig) config).name;
    boolean adminView = ((DescribeConfig) config).admin;
    if (asterixInstanceName != null) {
        AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE, State.ACTIVE, State.UNUSABLE);
        AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(asterixInstanceName);
        if (instance != null) {
            AsterixRuntimeState state = VerificationUtil.getAsterixRuntimeState(instance);
            boolean expectedRunning = instance.getState().equals(State.UNUSABLE) ? instance.getPreviousState().equals(State.ACTIVE) : !instance.getState().equals(State.INACTIVE);
            VerificationUtil.updateInstanceWithRuntimeDescription(instance, state, expectedRunning);
            ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
            LOGGER.info(instance.getDescription(adminView));
        } else {
            throw new InstallerException("Asterix instance by the name " + asterixInstanceName + " does not exist.");
        }
    } else {
        List<AsterixInstance> asterixInstances = ServiceProvider.INSTANCE.getLookupService().getAsterixInstances();
        if (asterixInstances.size() > 0) {
            for (AsterixInstance instance : asterixInstances) {
                AsterixRuntimeState state = VerificationUtil.getAsterixRuntimeState(instance);
                boolean expectedRunning = instance.getState().equals(State.UNUSABLE) ? instance.getPreviousState().equals(State.ACTIVE) : !instance.getState().equals(State.INACTIVE);
                VerificationUtil.updateInstanceWithRuntimeDescription(instance, state, expectedRunning);
                ServiceProvider.INSTANCE.getLookupService().updateAsterixInstance(instance);
                LOGGER.info(instance.getDescription(adminView));
            }
        } else {
            LOGGER.info("No Asterix instances found!");
        }
    }
}
Also used : AsterixInstance(org.apache.asterix.event.model.AsterixInstance) InstallerException(org.apache.asterix.installer.error.InstallerException) AsterixRuntimeState(org.apache.asterix.event.model.AsterixRuntimeState)

Aggregations

AsterixRuntimeState (org.apache.asterix.event.model.AsterixRuntimeState)9 AsterixInstance (org.apache.asterix.event.model.AsterixInstance)8 AsterixEventServiceClient (org.apache.asterix.event.management.AsterixEventServiceClient)4 Patterns (org.apache.asterix.event.schema.pattern.Patterns)4 ArrayList (java.util.ArrayList)3 ProcessInfo (org.apache.asterix.event.model.ProcessInfo)3 Node (org.apache.asterix.event.schema.cluster.Node)3 InstallerException (org.apache.asterix.installer.error.InstallerException)3 ClusterState (org.apache.asterix.common.api.IClusterManagementWork.ClusterState)2 Cluster (org.apache.asterix.event.schema.cluster.Cluster)2 Pattern (org.apache.asterix.event.schema.pattern.Pattern)2 ClusterStateWatcher (org.apache.asterix.event.service.ClusterStateWatcher)2 Test (org.junit.Test)2 Date (java.util.Date)1