use of org.apache.asterix.event.schema.cluster.Node in project asterixdb by apache.
the class AsterixEventServiceUtil method getMetadataNode.
private static Node getMetadataNode(String asterixInstanceName, Cluster cluster) {
Node metadataNode = null;
if (cluster.getMetadataNode() != null) {
for (Node node : cluster.getNode()) {
if (node.getId().equals(cluster.getMetadataNode())) {
metadataNode = node;
break;
}
}
} else {
Random random = new Random();
int nNodes = cluster.getNode().size();
metadataNode = cluster.getNode().get(random.nextInt(nNodes));
}
return metadataNode;
}
use of org.apache.asterix.event.schema.cluster.Node in project asterixdb by apache.
the class ReplicationManager method sendShutdownNotifiction.
/**
* Sends a shutdown event to remote replicas notifying them
* no more logs/files will be sent from this local replica.
*
* @throws IOException
*/
private void sendShutdownNotifiction() throws IOException {
Node node = new Node();
node.setId(nodeId);
node.setClusterIp(NetworkingUtil.getHostAddress(hostIPAddressFirstOctet));
Replica replica = new Replica(node);
ReplicaEvent event = new ReplicaEvent(replica, ClusterEventType.NODE_SHUTTING_DOWN);
ByteBuffer buffer = ReplicationProtocol.writeReplicaEventRequest(event);
Map<String, SocketChannel> replicaSockets = getActiveRemoteReplicasSockets();
sendRequest(replicaSockets, buffer);
closeReplicaSockets(replicaSockets);
}
use of org.apache.asterix.event.schema.cluster.Node in project asterixdb by apache.
the class ValidateConfig method validateCluster.
public boolean validateCluster(String clusterPath) throws Exception {
boolean valid = true;
Cluster cluster = null;
File f = new File(clusterPath);
List<String> ipAddresses = new ArrayList<String>();
if (!f.exists() || !f.isFile()) {
LOGGER.error(" Invalid path " + f.getAbsolutePath() + ERROR);
valid = false;
} else {
cluster = EventUtil.getCluster(clusterPath);
valid = valid & validateClusterProperties(cluster);
Set<String> servers = new HashSet<String>();
Set<String> serverIds = new HashSet<String>();
servers.add(cluster.getMasterNode().getClusterIp());
serverIds.add(cluster.getMasterNode().getId());
MasterNode masterNode = cluster.getMasterNode();
Node master = new Node(masterNode.getId(), masterNode.getClusterIp(), masterNode.getJavaHome(), masterNode.getLogDir(), null, null, null, null);
ipAddresses.add(masterNode.getClusterIp());
valid = valid & validateNodeConfiguration(master, cluster);
for (Node node : cluster.getNode()) {
servers.add(node.getClusterIp());
if (serverIds.contains(node.getId())) {
valid = false;
LOGGER.error("Duplicate node id :" + node.getId() + ERROR);
} else {
valid = valid & validateNodeConfiguration(node, cluster);
if (!ipAddresses.contains(node.getClusterIp())) {
ipAddresses.add(node.getClusterIp());
}
}
}
valid = valid & validateReplicationProperties(cluster);
}
if (valid) {
String username = cluster.getUsername();
if (username == null) {
username = System.getProperty("user.name");
}
valid = checkPasswordLessSSHLogin(username, ipAddresses);
}
return valid;
}
use of org.apache.asterix.event.schema.cluster.Node 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);
}
use of org.apache.asterix.event.schema.cluster.Node 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);
}
Aggregations