Search in sources :

Example 1 with IClusterManagementWork

use of org.apache.asterix.common.api.IClusterManagementWork in project asterixdb by apache.

the class ClusterLifecycleListener method notifyNodeJoin.

@Override
public void notifyNodeJoin(String nodeId, Map<IOption, Object> ncConfiguration) throws HyracksException {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("NC: " + nodeId + " joined");
    }
    ClusterStateManager.INSTANCE.addNCConfiguration(nodeId, ncConfiguration);
    //if metadata node rejoining, we need to rebind the proxy connection when it is active again.
    if (!ClusterStateManager.INSTANCE.isMetadataNodeActive()) {
        MetadataManager.INSTANCE.rebindMetadataNode();
    }
    Set<String> nodeAddition = new HashSet<>();
    nodeAddition.add(nodeId);
    updateProgress(ClusterEventType.NODE_JOIN, nodeAddition);
    Set<IClusterEventsSubscriber> subscribers = ClusterManagerProvider.getClusterManager().getRegisteredClusterEventSubscribers();
    Set<IClusterManagementWork> work = new HashSet<>();
    for (IClusterEventsSubscriber sub : subscribers) {
        Set<IClusterManagementWork> workRequest = sub.notifyNodeJoin(nodeId);
        work.addAll(workRequest);
    }
    if (!work.isEmpty()) {
        executeWorkSet(work);
    }
}
Also used : IClusterEventsSubscriber(org.apache.asterix.common.api.IClusterEventsSubscriber) IClusterManagementWork(org.apache.asterix.common.api.IClusterManagementWork) HashSet(java.util.HashSet)

Example 2 with IClusterManagementWork

use of org.apache.asterix.common.api.IClusterManagementWork in project asterixdb by apache.

the class ClusterLifecycleListener method notifyNodeFailure.

@Override
public void notifyNodeFailure(Collection<String> deadNodeIds) throws HyracksException {
    for (String deadNode : deadNodeIds) {
        if (LOGGER.isLoggable(Level.INFO)) {
            LOGGER.info("NC: " + deadNode + " left");
        }
        ClusterStateManager.INSTANCE.removeNCConfiguration(deadNode);
        //if metadata node failed, we need to rebind the proxy connection when it is active again
        if (!ClusterStateManager.INSTANCE.isMetadataNodeActive()) {
            MetadataManager.INSTANCE.rebindMetadataNode();
        }
    }
    updateProgress(ClusterEventType.NODE_FAILURE, deadNodeIds);
    Set<IClusterEventsSubscriber> subscribers = ClusterManagerProvider.getClusterManager().getRegisteredClusterEventSubscribers();
    Set<IClusterManagementWork> work = new HashSet<>();
    for (IClusterEventsSubscriber sub : subscribers) {
        Set<IClusterManagementWork> workRequest = sub.notifyNodeFailure(deadNodeIds);
        work.addAll(workRequest);
    }
    if (!work.isEmpty()) {
        executeWorkSet(work);
    }
}
Also used : IClusterEventsSubscriber(org.apache.asterix.common.api.IClusterEventsSubscriber) IClusterManagementWork(org.apache.asterix.common.api.IClusterManagementWork) HashSet(java.util.HashSet)

Example 3 with IClusterManagementWork

use of org.apache.asterix.common.api.IClusterManagementWork in project asterixdb by apache.

the class ClusterWorkExecutor method run.

@Override
public void run() {
    while (true) {
        try {
            Set<IClusterManagementWork> workSet = inbox.take();
            int nodesToAdd = 0;
            Set<String> nodesToRemove = new HashSet<>();
            Set<IClusterManagementWork> nodeAdditionRequests = new HashSet<>();
            Set<IClusterManagementWork> nodeRemovalRequests = new HashSet<>();
            for (IClusterManagementWork w : workSet) {
                switch(w.getClusterManagementWorkType()) {
                    case ADD_NODE:
                        if (nodesToAdd < ((AddNodeWork) w).getNumberOfNodesRequested()) {
                            nodesToAdd = ((AddNodeWork) w).getNumberOfNodesRequested();
                        }
                        nodeAdditionRequests.add(w);
                        break;
                    case REMOVE_NODE:
                        nodesToRemove.addAll(((RemoveNodeWork) w).getNodesToBeRemoved());
                        nodeRemovalRequests.add(w);
                        break;
                }
            }
            Set<Node> addedNodes = new HashSet<>();
            for (int i = 0; i < nodesToAdd; i++) {
                Node node = ClusterStateManager.INSTANCE.getAvailableSubstitutionNode();
                if (node != null) {
                    try {
                        ClusterManagerProvider.getClusterManager().addNode(appCtx, node);
                        addedNodes.add(node);
                        if (LOGGER.isLoggable(Level.INFO)) {
                            LOGGER.info("Added NC at:" + node.getId());
                        }
                    } catch (AsterixException e) {
                        if (LOGGER.isLoggable(Level.WARNING)) {
                            LOGGER.warning("Unable to add NC at:" + node.getId());
                        }
                        e.printStackTrace();
                    }
                } else {
                    if (LOGGER.isLoggable(Level.WARNING)) {
                        LOGGER.warning("Unable to add NC: no more available nodes");
                    }
                }
            }
        } catch (InterruptedException e) {
            if (LOGGER.isLoggable(Level.SEVERE)) {
                LOGGER.severe("interruped" + e.getMessage());
            }
            throw new IllegalStateException(e);
        } catch (Exception e) {
            if (LOGGER.isLoggable(Level.SEVERE)) {
                LOGGER.severe("Unexpected exception in handling cluster event" + e.getMessage());
            }
        }
    }
}
Also used : AsterixException(org.apache.asterix.common.exceptions.AsterixException) Node(org.apache.asterix.event.schema.cluster.Node) IClusterManagementWork(org.apache.asterix.common.api.IClusterManagementWork) AsterixException(org.apache.asterix.common.exceptions.AsterixException) HashSet(java.util.HashSet)

Example 4 with IClusterManagementWork

use of org.apache.asterix.common.api.IClusterManagementWork in project asterixdb by apache.

the class ClusterLifecycleListener method executeWorkSet.

private void executeWorkSet(Set<IClusterManagementWork> workSet) {
    int nodesToAdd = 0;
    Set<String> nodesToRemove = new HashSet<>();
    Set<AddNodeWork> nodeAdditionRequests = new HashSet<>();
    Set<IClusterManagementWork> nodeRemovalRequests = new HashSet<>();
    for (IClusterManagementWork w : workSet) {
        switch(w.getClusterManagementWorkType()) {
            case ADD_NODE:
                if (nodesToAdd < ((AddNodeWork) w).getNumberOfNodesRequested()) {
                    nodesToAdd = ((AddNodeWork) w).getNumberOfNodesRequested();
                }
                nodeAdditionRequests.add((AddNodeWork) w);
                break;
            case REMOVE_NODE:
                nodesToRemove.addAll(((RemoveNodeWork) w).getNodesToBeRemoved());
                nodeRemovalRequests.add(w);
                RemoveNodeWorkResponse response = new RemoveNodeWorkResponse((RemoveNodeWork) w, Status.IN_PROGRESS);
                pendingWorkResponses.add(response);
                break;
        }
    }
    List<String> addedNodes = new ArrayList<>();
    String asterixInstanceName = ClusterProperties.INSTANCE.getCluster().getInstanceName();
    for (int i = 0; i < nodesToAdd; i++) {
        Node node = ClusterStateManager.INSTANCE.getAvailableSubstitutionNode();
        if (node != null) {
            try {
                ClusterManagerProvider.getClusterManager().addNode(appCtx, node);
                addedNodes.add(asterixInstanceName + "_" + node.getId());
                if (LOGGER.isLoggable(Level.INFO)) {
                    LOGGER.info("Added NC at:" + node.getId());
                }
            } catch (AsterixException e) {
                if (LOGGER.isLoggable(Level.WARNING)) {
                    LOGGER.warning("Unable to add NC at:" + node.getId());
                }
                e.printStackTrace();
            }
        } else {
            if (LOGGER.isLoggable(Level.WARNING)) {
                LOGGER.warning("Unable to add NC: no more available nodes");
            }
        }
    }
    for (AddNodeWork w : nodeAdditionRequests) {
        int n = w.getNumberOfNodesRequested();
        List<String> nodesToBeAddedForWork = new ArrayList<>();
        for (int i = 0; i < n && i < addedNodes.size(); i++) {
            nodesToBeAddedForWork.add(addedNodes.get(i));
        }
        if (nodesToBeAddedForWork.isEmpty()) {
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info("Unable to satisfy request by " + w);
            }
            AddNodeWorkResponse response = new AddNodeWorkResponse(w, nodesToBeAddedForWork);
            response.setStatus(Status.FAILURE);
            w.getSourceSubscriber().notifyRequestCompletion(response);
        } else {
            AddNodeWorkResponse response = new AddNodeWorkResponse(w, nodesToBeAddedForWork);
            pendingWorkResponses.add(response);
        }
    }
}
Also used : Node(org.apache.asterix.event.schema.cluster.Node) IClusterManagementWork(org.apache.asterix.common.api.IClusterManagementWork) ArrayList(java.util.ArrayList) AsterixException(org.apache.asterix.common.exceptions.AsterixException) RemoveNodeWorkResponse(org.apache.asterix.metadata.cluster.RemoveNodeWorkResponse) AddNodeWork(org.apache.asterix.metadata.cluster.AddNodeWork) AddNodeWorkResponse(org.apache.asterix.metadata.cluster.AddNodeWorkResponse) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)4 IClusterManagementWork (org.apache.asterix.common.api.IClusterManagementWork)4 IClusterEventsSubscriber (org.apache.asterix.common.api.IClusterEventsSubscriber)2 AsterixException (org.apache.asterix.common.exceptions.AsterixException)2 Node (org.apache.asterix.event.schema.cluster.Node)2 ArrayList (java.util.ArrayList)1 AddNodeWork (org.apache.asterix.metadata.cluster.AddNodeWork)1 AddNodeWorkResponse (org.apache.asterix.metadata.cluster.AddNodeWorkResponse)1 RemoveNodeWorkResponse (org.apache.asterix.metadata.cluster.RemoveNodeWorkResponse)1