use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.
the class ZookeeperUtil method getAsterixInstances.
@Override
public List<AsterixInstance> getAsterixInstances() throws Exception {
List<String> instanceNames = zk.getChildren(ASTERIX_INSTANCE_BASE_PATH, false);
List<AsterixInstance> asterixInstances = new ArrayList<AsterixInstance>();
String path;
for (String instanceName : instanceNames) {
path = ASTERIX_INSTANCE_BASE_PATH + File.separator + instanceName;
byte[] asterixInstanceBytes = zk.getData(path, false, new Stat());
asterixInstances.add(readAsterixInstanceObject(asterixInstanceBytes));
}
return asterixInstances;
}
use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.
the class AsterixEventServiceUtil method validateAsterixInstanceExists.
public static AsterixInstance validateAsterixInstanceExists(String name, State... permissibleStates) throws Exception {
AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(name);
if (instance == null) {
throw new EventException("Asterix instance by name " + name + " does not exist.");
}
boolean valid = false;
for (State state : permissibleStates) {
if (state.equals(instance.getState())) {
valid = true;
break;
}
}
if (!valid) {
throw new EventException("Asterix instance by the name " + name + " is in " + instance.getState() + " state ");
}
return instance;
}
use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.
the class AsterixEventServiceUtil method evaluateConflictWithOtherInstances.
public static void evaluateConflictWithOtherInstances(AsterixInstance instance) throws Exception {
List<AsterixInstance> existingInstances = ServiceProvider.INSTANCE.getLookupService().getAsterixInstances();
List<String> usedIps = new ArrayList<String>();
String masterIp = instance.getCluster().getMasterNode().getClusterIp();
for (Node node : instance.getCluster().getNode()) {
usedIps.add(node.getClusterIp());
}
usedIps.add(instance.getCluster().getMasterNode().getClusterIp());
boolean conflictFound = false;
AsterixInstance conflictingInstance = null;
for (AsterixInstance existing : existingInstances) {
if (existing.getState().equals(State.INACTIVE)) {
continue;
}
InetAddress extantAddress = InetAddress.getByName(existing.getCluster().getMasterNode().getClusterIp());
InetAddress masterAddress = InetAddress.getByName(masterIp);
if (extantAddress.equals(masterAddress)) {
conflictingInstance = existing;
break;
}
for (Node n : existing.getCluster().getNode()) {
if (usedIps.contains(n.getClusterIp())) {
conflictFound = true;
conflictingInstance = existing;
break;
}
}
}
if (conflictFound) {
throw new Exception("Cluster definition conflicts with an existing instance of Asterix: " + conflictingInstance.getName());
}
}
use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.
the class AsterixEventServiceUtil method createAsterixInstance.
public static AsterixInstance createAsterixInstance(String asterixInstanceName, Cluster cluster, AsterixConfiguration asterixConfiguration) throws IOException {
Node metadataNode = getMetadataNode(asterixInstanceName, cluster);
String asterixZipName = asterixZipName();
String asterixVersion = asterixZipName.substring("asterix-server-".length(), asterixZipName.indexOf("-binary-assembly"));
return new AsterixInstance(asterixInstanceName, cluster, asterixConfiguration, metadataNode.getId(), asterixVersion);
}
use of org.apache.asterix.event.model.AsterixInstance in project asterixdb by apache.
the class AlterConfig method execCommand.
@Override
protected void execCommand() throws Exception {
InstallerDriver.initConfig(true);
String instanceName = ((AlterConfig) config).name;
AsterixEventServiceUtil.validateAsterixInstanceExists(instanceName, State.INACTIVE);
ILookupService lookupService = ServiceProvider.INSTANCE.getLookupService();
AsterixInstance instance = ServiceProvider.INSTANCE.getLookupService().getAsterixInstance(instanceName);
AsterixEventServiceUtil.createClusterProperties(instance.getCluster(), instance.getAsterixConfiguration());
AsterixConfiguration asterixConfiguration = InstallerUtil.getAsterixConfiguration(((AlterConfig) config).confPath);
instance.setAsterixConfiguration(asterixConfiguration);
instance.setModifiedTimestamp(new Date());
lookupService.updateAsterixInstance(instance);
LOGGER.info("Altered configuration settings for Asterix instance: " + instanceName);
}
Aggregations