Search in sources :

Example 1 with ToolPlugin

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

the class NodeResource method checkNodeStatus.

/**
 * Check the status of a node. This method need to be public for the CGLIB proxying.
 *
 * @param node
 *            The node identifier.
 * @param parameters
 *            Node parameters used to check the status.
 * @return The node status.
 */
public NodeStatus checkNodeStatus(final String node, final Map<String, String> parameters) {
    boolean isUp = false;
    log.info("Check status of node {}", node);
    try {
        // Find the plug-in associated to the requested node
        final ToolPlugin plugin = locator.getResourceExpected(node, ToolPlugin.class);
        // Call service which check status
        isUp = plugin.checkStatus(node, parameters);
    } catch (final Exception e) {
        // NOSONAR
        // Do not pollute logs with this failures
        // Service is down when an exception is thrown.
        log.warn("Check status of node {} failed with {}: {}", node, e.getClass(), e.getMessage());
    }
    return NodeStatus.getValue(isUp);
}
Also used : ToolPlugin(org.ligoj.app.api.ToolPlugin) ValidationJsonException(org.ligoj.bootstrap.core.validation.ValidationJsonException) BusinessException(org.ligoj.bootstrap.core.resource.BusinessException)

Example 2 with ToolPlugin

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

the class NodeResource method checkSubscriptionStatus.

/**
 * Check status for a subscription.
 *
 * @param subscription
 *            Subscription entity.
 * @param parameters
 *            Parameters of a subscription.
 * @return status of given subscription.
 */
public SubscriptionStatusWithData checkSubscriptionStatus(final Subscription subscription, final Map<String, String> parameters) {
    final String node = subscription.getNode().getId();
    try {
        log.info("Check status of a subscription attached to {}...", node);
        // Find the plug-in associated to the requested node
        final ToolPlugin toolPlugin = locator.getResourceExpected(node, ToolPlugin.class);
        // Call service which check status
        final SubscriptionStatusWithData status = toolPlugin.checkSubscriptionStatus(subscription.getId(), node, parameters);
        status.setNode(node);
        log.info("Check status of a subscription attached to {} succeed", node);
        return status;
    } catch (final Exception e) {
        // NOSONAR
        // Do not pollute logs with this failures
        // Service is down when an exception is thrown, log the error
        // without trace
        log.warn("Check status of a subscription attached to {} failed : {}", node, e.getMessage());
    }
    return new SubscriptionStatusWithData(false);
}
Also used : SubscriptionStatusWithData(org.ligoj.app.api.SubscriptionStatusWithData) ToolPlugin(org.ligoj.app.api.ToolPlugin) ValidationJsonException(org.ligoj.bootstrap.core.validation.ValidationJsonException) BusinessException(org.ligoj.bootstrap.core.resource.BusinessException)

Aggregations

ToolPlugin (org.ligoj.app.api.ToolPlugin)2 BusinessException (org.ligoj.bootstrap.core.resource.BusinessException)2 ValidationJsonException (org.ligoj.bootstrap.core.validation.ValidationJsonException)2 SubscriptionStatusWithData (org.ligoj.app.api.SubscriptionStatusWithData)1