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;
}
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);
}
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;
}
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);
}
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();
}
Aggregations