Search in sources :

Example 1 with NodeStatus

use of org.ligoj.app.api.NodeStatus in project ligoj-api by ligoj.

the class NodeResource method checkSubscriptionStatus.

/**
 * Check status subscription.
 *
 * @param node
 *            node where we must check subscriptions
 * @param status
 *            node status
 */
protected void checkSubscriptionStatus(final Node node, final NodeStatus status) {
    final Map<String, String> nodeParameters = pvResource.getNodeParameters(node.getId());
    // Retrieve subscriptions where parameters are redefined.
    // Other subscriptions get the node's status.
    final Map<Subscription, Map<String, String>> subscriptions = findSubscriptionsWithParams(node.getId());
    NodeStatus newStatus = status;
    if (status == null) {
        // Node status is unknown for now, need a check
        newStatus = NodeStatus.getValue(self.checkNodeStatus(node.getId(), nodeParameters).isUp());
        // Update the node status
        eventResource.registerEvent(node, EventType.STATUS, newStatus.name());
    }
    // Check the subscriptions
    if (newStatus.isUp()) {
        // Check only the subscription in UP nodes
        checkNodeSubscriptions(node, nodeParameters, subscriptions);
    } else {
        // All subscription of this are marked as DOWN
        log.info("Node {} is DOWN, as well for {} related subscriptions", node.getId(), subscriptions.size());
        subscriptions.entrySet().forEach(s -> eventResource.registerEvent(s.getKey(), EventType.STATUS, NodeStatus.DOWN.name()));
    }
}
Also used : Subscription(org.ligoj.app.model.Subscription) Map(java.util.Map) HashMap(java.util.HashMap) NodeStatus(org.ligoj.app.api.NodeStatus)

Example 2 with NodeStatus

use of org.ligoj.app.api.NodeStatus in project ligoj-api by ligoj.

the class NodeResource method checkNodeSubscriptions.

/**
 * Check the subscriptions of each subscription related to given node.
 */
private void checkNodeSubscriptions(final Node node, final Map<String, String> nodeParameters, final Map<Subscription, Map<String, String>> subscriptions) {
    int counter = 0;
    for (final Entry<Subscription, Map<String, String>> subscription : subscriptions.entrySet()) {
        // For each subscription, check status
        log.info("Check all subscriptions of node {} : {}/{} ...", node.getId(), counter + 1, subscriptions.size());
        final Map<String, String> parameters = new HashMap<>(nodeParameters);
        parameters.putAll(subscription.getValue());
        final NodeStatus subscriptionStatus = self.checkSubscriptionStatus(subscription.getKey(), parameters).getStatus();
        eventResource.registerEvent(subscription.getKey(), EventType.STATUS, subscriptionStatus.name());
        counter++;
    }
}
Also used : HashMap(java.util.HashMap) Subscription(org.ligoj.app.model.Subscription) Map(java.util.Map) HashMap(java.util.HashMap) NodeStatus(org.ligoj.app.api.NodeStatus)

Example 3 with NodeStatus

use of org.ligoj.app.api.NodeStatus in project ligoj-api by ligoj.

the class NodeResource method checkNodeStatus.

/**
 * Check the status of a node.
 *
 * @param node
 *            The node to check.
 * @return the new status.
 */
private NodeStatus checkNodeStatus(final Node node) {
    final Map<String, String> parameters = pvResource.getNodeParameters(node.getId());
    final NodeStatus status = self.checkNodeStatus(node.getId(), parameters);
    if (eventResource.registerEvent(node, EventType.STATUS, status.name())) {
        checkSubscriptionStatus(node, status);
    }
    return status;
}
Also used : NodeStatus(org.ligoj.app.api.NodeStatus)

Aggregations

NodeStatus (org.ligoj.app.api.NodeStatus)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Subscription (org.ligoj.app.model.Subscription)2