Search in sources :

Example 31 with Patterns

use of org.apache.asterix.event.schema.pattern.Patterns 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 32 with Patterns

use of org.apache.asterix.event.schema.pattern.Patterns 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 33 with Patterns

use of org.apache.asterix.event.schema.pattern.Patterns 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)

Example 34 with Patterns

use of org.apache.asterix.event.schema.pattern.Patterns 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 35 with Patterns

use of org.apache.asterix.event.schema.pattern.Patterns in project asterixdb by apache.

the class LogConfig method execCommand.

@Override
protected void execCommand() throws Exception {
    InstallerDriver.initConfig(true);
    String asterixInstanceName = ((LogConfig) config).name;
    AsterixInstance instance = AsterixEventServiceUtil.validateAsterixInstanceExists(asterixInstanceName, State.INACTIVE, State.UNUSABLE, State.ACTIVE);
    PatternCreator pc = PatternCreator.INSTANCE;
    AsterixEventServiceClient eventrixClient = AsterixEventService.getAsterixEventServiceClient(instance.getCluster(), true, false);
    String outputDir = ((LogConfig) config).outputDir == null ? InstallerDriver.getManagixHome() + File.separator + "logdump" : ((LogConfig) config).outputDir;
    File f = new File(outputDir);
    String outputDirPath = f.getAbsolutePath();
    if (!f.exists()) {
        boolean success = f.mkdirs();
        if (!success) {
            throw new InstallerException("Unable to create output directory:" + outputDirPath);
        }
    }
    Patterns transferLogPattern = pc.getGenerateLogPattern(instance.getCluster(), outputDirPath);
    eventrixClient.submit(transferLogPattern);
    File outputDirFile = new File(outputDirPath);
    final String destFileName = "log_" + new Date().toString().replace(' ', '_') + ".zip";
    File destFile = new File(outputDirFile, destFileName);
    AsterixEventServiceUtil.zipDir(outputDirFile, destFile);
    String[] filesToDelete = outputDirFile.list(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String name) {
            return !name.equals(destFileName);
        }
    });
    for (String fileS : filesToDelete) {
        f = new File(outputDirFile, fileS);
        if (f.isDirectory()) {
            FileUtils.deleteDirectory(f);
        } else {
            f.delete();
        }
    }
    LOGGER.info("Log zip archive created at " + destFile.getAbsolutePath());
}
Also used : Date(java.util.Date) FilenameFilter(java.io.FilenameFilter) AsterixEventServiceClient(org.apache.asterix.event.management.AsterixEventServiceClient) PatternCreator(org.apache.asterix.event.util.PatternCreator) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) InstallerException(org.apache.asterix.installer.error.InstallerException) File(java.io.File) Patterns(org.apache.asterix.event.schema.pattern.Patterns)

Aggregations

Patterns (org.apache.asterix.event.schema.pattern.Patterns)35 ArrayList (java.util.ArrayList)24 Pattern (org.apache.asterix.event.schema.pattern.Pattern)24 Node (org.apache.asterix.event.schema.cluster.Node)21 Nodeid (org.apache.asterix.event.schema.pattern.Nodeid)17 Value (org.apache.asterix.event.schema.pattern.Value)17 Event (org.apache.asterix.event.schema.pattern.Event)16 Cluster (org.apache.asterix.event.schema.cluster.Cluster)15 AsterixInstance (org.apache.asterix.event.model.AsterixInstance)12 AsterixEventServiceClient (org.apache.asterix.event.management.AsterixEventServiceClient)7 File (java.io.File)5 Date (java.util.Date)4 AsterixRuntimeState (org.apache.asterix.event.model.AsterixRuntimeState)4 BackupInfo (org.apache.asterix.event.model.BackupInfo)3 PatternCreator (org.apache.asterix.event.util.PatternCreator)3 InstallerException (org.apache.asterix.installer.error.InstallerException)3 ClusterState (org.apache.asterix.common.api.IClusterManagementWork.ClusterState)2 BackupType (org.apache.asterix.event.model.BackupInfo.BackupType)2 ProcessInfo (org.apache.asterix.event.model.ProcessInfo)2 ClusterStateWatcher (org.apache.asterix.event.service.ClusterStateWatcher)2