Search in sources :

Example 6 with AsterixInstance

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;
}
Also used : Stat(org.apache.zookeeper.data.Stat) ArrayList(java.util.ArrayList) AsterixInstance(org.apache.asterix.event.model.AsterixInstance)

Example 7 with AsterixInstance

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;
}
Also used : EventException(org.apache.asterix.event.error.EventException) State(org.apache.asterix.event.model.AsterixInstance.State) AsterixInstance(org.apache.asterix.event.model.AsterixInstance)

Example 8 with AsterixInstance

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());
    }
}
Also used : Node(org.apache.asterix.event.schema.cluster.Node) ArrayList(java.util.ArrayList) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) InetAddress(java.net.InetAddress) EventException(org.apache.asterix.event.error.EventException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException)

Example 9 with AsterixInstance

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);
}
Also used : Node(org.apache.asterix.event.schema.cluster.Node) AsterixInstance(org.apache.asterix.event.model.AsterixInstance)

Example 10 with AsterixInstance

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);
}
Also used : AsterixConfiguration(org.apache.asterix.common.configuration.AsterixConfiguration) AsterixInstance(org.apache.asterix.event.model.AsterixInstance) Date(java.util.Date) ILookupService(org.apache.asterix.event.service.ILookupService)

Aggregations

AsterixInstance (org.apache.asterix.event.model.AsterixInstance)25 Patterns (org.apache.asterix.event.schema.pattern.Patterns)12 AsterixRuntimeState (org.apache.asterix.event.model.AsterixRuntimeState)8 AsterixEventServiceClient (org.apache.asterix.event.management.AsterixEventServiceClient)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)5 Node (org.apache.asterix.event.schema.cluster.Node)5 Pattern (org.apache.asterix.event.schema.pattern.Pattern)4 InstallerException (org.apache.asterix.installer.error.InstallerException)4 PatternCreator (org.apache.asterix.event.util.PatternCreator)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 JAXBException (javax.xml.bind.JAXBException)2 ClusterState (org.apache.asterix.common.api.IClusterManagementWork.ClusterState)2 EventException (org.apache.asterix.event.error.EventException)2 BackupInfo (org.apache.asterix.event.model.BackupInfo)2 ProcessInfo (org.apache.asterix.event.model.ProcessInfo)2 Cluster (org.apache.asterix.event.schema.cluster.Cluster)2 ClusterStateWatcher (org.apache.asterix.event.service.ClusterStateWatcher)2 ILookupService (org.apache.asterix.event.service.ILookupService)2