Search in sources :

Example 21 with Node

use of org.apache.asterix.event.schema.cluster.Node in project asterixdb by apache.

the class EventUtil method getCandidateLocations.

public static List<Node> getCandidateLocations(Pattern pattern, Cluster cluster) {
    ValueType value = new ValueType(pattern.getEvent().getNodeid().getValue());
    List<Node> candidateList = new ArrayList<Node>();
    switch(value.getType()) {
        case ABS:
            candidateList.add(getNodeFromId(value.getAbsoluteValue(), cluster));
            break;
        case RANDOM_RANGE:
            boolean anyOption = false;
            String[] values = value.getRangeSet();
            for (String v : values) {
                if (v.equalsIgnoreCase("ANY")) {
                    anyOption = true;
                }
            }
            if (anyOption) {
                for (Node node : cluster.getNode()) {
                    candidateList.add(node);
                }
            } else {
                boolean found = false;
                for (String v : values) {
                    for (Node node : cluster.getNode()) {
                        if (node.getId().equals(v)) {
                            candidateList.add(node);
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        throw new IllegalStateException("Unknonw nodeId : " + v);
                    }
                    found = false;
                }
            }
            String[] excluded = value.getRangeExcluded();
            if (excluded != null && excluded.length > 0) {
                List<Node> markedForRemoval = new ArrayList<Node>();
                for (String exclusion : excluded) {
                    for (Node node : candidateList) {
                        if (node.getId().equals(exclusion)) {
                            markedForRemoval.add(node);
                        }
                    }
                }
                candidateList.removeAll(markedForRemoval);
            }
            break;
        case RANDOM_MIN_MAX:
            throw new IllegalStateException(" Invalid value configured for location");
    }
    return candidateList;
}
Also used : Node(org.apache.asterix.event.schema.cluster.Node) ArrayList(java.util.ArrayList)

Example 22 with Node

use of org.apache.asterix.event.schema.cluster.Node in project asterixdb by apache.

the class EventUtil method getNodeFromId.

private static Node getNodeFromId(String nodeid, Cluster cluster) {
    if (nodeid.equals(EventDriver.CLIENT_NODE.getId())) {
        return EventDriver.CLIENT_NODE;
    }
    if (nodeid.equals(cluster.getMasterNode().getId())) {
        String logDir = cluster.getMasterNode().getLogDir() == null ? cluster.getLogDir() : cluster.getMasterNode().getLogDir();
        String javaHome = cluster.getMasterNode().getJavaHome() == null ? cluster.getJavaHome() : cluster.getMasterNode().getJavaHome();
        return new Node(cluster.getMasterNode().getId(), cluster.getMasterNode().getClusterIp(), javaHome, logDir, null, null, cluster.getMasterNode().getDebugPort(), null);
    }
    List<Node> nodeList = cluster.getNode();
    for (Node node : nodeList) {
        if (node.getId().equals(nodeid)) {
            return node;
        }
    }
    StringBuilder buffer = new StringBuilder();
    buffer.append(EventDriver.CLIENT_NODE.getId() + ",");
    buffer.append(cluster.getMasterNode().getId() + ",");
    for (Node v : cluster.getNode()) {
        buffer.append(v.getId() + ",");
    }
    buffer.deleteCharAt(buffer.length() - 1);
    throw new IllegalArgumentException("Unknown node id :" + nodeid + " valid ids:" + buffer);
}
Also used : Node(org.apache.asterix.event.schema.cluster.Node)

Example 23 with Node

use of org.apache.asterix.event.schema.cluster.Node in project asterixdb by apache.

the class Replica method create.

public static Replica create(DataInput input) throws IOException {
    Node node = new Node();
    Replica replica = new Replica(node);
    replica.readFields(input);
    return replica;
}
Also used : Node(org.apache.asterix.event.schema.cluster.Node)

Example 24 with Node

use of org.apache.asterix.event.schema.cluster.Node in project asterixdb by apache.

the class AsterixEventServiceClient method initPattern.

private Patterns initPattern(String eventsDir) throws Exception {
    Nodeid nodeid = new Nodeid(new Value(null, EventDriver.CLIENT_NODE.getId()));
    List<Pattern> patternList = new ArrayList<Pattern>();
    String workingDir = cluster.getWorkingDir().getDir();
    String username = cluster.getUsername() == null ? System.getProperty("user.name") : cluster.getUsername();
    patternList.add(getDirectoryTransferPattern(username, eventsDir, nodeid, cluster.getMasterNode().getClusterIp(), workingDir));
    JAXBContext ctx = JAXBContext.newInstance(Configuration.class);
    Marshaller marshaller = ctx.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    String outputPathDir = System.getProperty("java.io.tmpdir") + File.separator + "conf-" + System.getProperty("user.name");
    new File(outputPathDir).mkdirs();
    String outputPath = outputPathDir + File.separator + "configuration.xml";
    marshaller.marshal(configuration, new FileOutputStream(outputPath));
    patternList.add(getFileTransferPattern(username, outputPath, nodeid, cluster.getMasterNode().getClusterIp(), workingDir));
    if (!cluster.getWorkingDir().isNFS()) {
        for (Node node : cluster.getNode()) {
            patternList.add(getDirectoryTransferPattern(username, eventsDir, nodeid, node.getClusterIp(), workingDir));
        }
    }
    return new Patterns(patternList);
}
Also used : Pattern(org.apache.asterix.event.schema.pattern.Pattern) Marshaller(javax.xml.bind.Marshaller) FileOutputStream(java.io.FileOutputStream) Node(org.apache.asterix.event.schema.cluster.Node) Nodeid(org.apache.asterix.event.schema.pattern.Nodeid) Value(org.apache.asterix.event.schema.pattern.Value) ArrayList(java.util.ArrayList) JAXBContext(javax.xml.bind.JAXBContext) File(java.io.File) Patterns(org.apache.asterix.event.schema.pattern.Patterns)

Example 25 with Node

use of org.apache.asterix.event.schema.cluster.Node in project asterixdb by apache.

the class AsterixEventServiceUtil method writeAsterixConfigurationFile.

private static void writeAsterixConfigurationFile(AsterixInstance asterixInstance) throws IOException, JAXBException {
    String asterixInstanceName = asterixInstance.getName();
    Cluster cluster = asterixInstance.getCluster();
    String metadataNodeId = asterixInstance.getMetadataNodeId();
    AsterixConfiguration configuration = asterixInstance.getAsterixConfiguration();
    configuration.setInstanceName(asterixInstanceName);
    configuration.setMetadataNode(asterixInstanceName + "_" + metadataNodeId);
    List<Store> stores = new ArrayList<Store>();
    String storeDir = cluster.getStore().trim();
    for (Node node : cluster.getNode()) {
        String iodevices = node.getIodevices() == null ? cluster.getIodevices() : node.getIodevices();
        String[] nodeIdDevice = iodevices.split(",");
        StringBuilder nodeStores = new StringBuilder();
        for (int i = 0; i < nodeIdDevice.length; i++) {
            nodeStores.append(nodeIdDevice[i] + File.separator + storeDir + ",");
        }
        //remove last comma
        nodeStores.deleteCharAt(nodeStores.length() - 1);
        stores.add(new Store(asterixInstanceName + "_" + node.getId(), nodeStores.toString()));
    }
    configuration.setStore(stores);
    List<Coredump> coredump = new ArrayList<Coredump>();
    List<TransactionLogDir> txnLogDirs = new ArrayList<TransactionLogDir>();
    for (Node node : cluster.getNode()) {
        String coredumpdir = node.getLogDir() == null ? cluster.getLogDir() : node.getLogDir();
        coredump.add(new Coredump(asterixInstanceName + "_" + node.getId(), coredumpdir + File.separator + asterixInstanceName + "_" + node.getId()));
        String txnLogDir = node.getTxnLogDir() == null ? cluster.getTxnLogDir() : node.getTxnLogDir();
        txnLogDirs.add(new TransactionLogDir(asterixInstanceName + "_" + node.getId(), txnLogDir));
    }
    configuration.setCoredump(coredump);
    configuration.setTransactionLogDir(txnLogDirs);
    File asterixConfDir = new File(AsterixEventService.getAsterixDir() + File.separator + asterixInstanceName);
    asterixConfDir.mkdirs();
    JAXBContext ctx = JAXBContext.newInstance(AsterixConfiguration.class);
    Marshaller marshaller = ctx.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    FileOutputStream os = new FileOutputStream(asterixConfDir + File.separator + ASTERIX_CONFIGURATION_FILE);
    marshaller.marshal(configuration, os);
    os.close();
}
Also used : Marshaller(javax.xml.bind.Marshaller) AsterixConfiguration(org.apache.asterix.common.configuration.AsterixConfiguration) TransactionLogDir(org.apache.asterix.common.configuration.TransactionLogDir) Node(org.apache.asterix.event.schema.cluster.Node) ArrayList(java.util.ArrayList) Cluster(org.apache.asterix.event.schema.cluster.Cluster) Store(org.apache.asterix.common.configuration.Store) JAXBContext(javax.xml.bind.JAXBContext) FileOutputStream(java.io.FileOutputStream) Coredump(org.apache.asterix.common.configuration.Coredump) JarFile(java.util.jar.JarFile) File(java.io.File)

Aggregations

Node (org.apache.asterix.event.schema.cluster.Node)43 ArrayList (java.util.ArrayList)29 Pattern (org.apache.asterix.event.schema.pattern.Pattern)21 Patterns (org.apache.asterix.event.schema.pattern.Patterns)21 Cluster (org.apache.asterix.event.schema.cluster.Cluster)20 Nodeid (org.apache.asterix.event.schema.pattern.Nodeid)16 Value (org.apache.asterix.event.schema.pattern.Value)16 Event (org.apache.asterix.event.schema.pattern.Event)15 File (java.io.File)5 HashSet (java.util.HashSet)5 AsterixInstance (org.apache.asterix.event.model.AsterixInstance)5 FileOutputStream (java.io.FileOutputStream)3 JAXBContext (javax.xml.bind.JAXBContext)3 Marshaller (javax.xml.bind.Marshaller)3 AsterixEventServiceClient (org.apache.asterix.event.management.AsterixEventServiceClient)3 AsterixRuntimeState (org.apache.asterix.event.model.AsterixRuntimeState)3 ProcessInfo (org.apache.asterix.event.model.ProcessInfo)3 Date (java.util.Date)2 IClusterManagementWork (org.apache.asterix.common.api.IClusterManagementWork)2 AsterixException (org.apache.asterix.common.exceptions.AsterixException)2