Search in sources :

Example 1 with NodeCommandMetadata

use of org.killbill.billing.util.nodes.NodeCommandMetadata in project killbill by killbill.

the class NodesInfoResource method triggerNodeCommand.

@TimedResource
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Trigger a node command")
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid node command supplied") })
public Response triggerNodeCommand(final NodeCommandJson json, @QueryParam(QUERY_LOCAL_NODE_ONLY) @DefaultValue("false") final Boolean localNodeOnly, @HeaderParam(HDR_CREATED_BY) final String createdBy, @HeaderParam(HDR_REASON) final String reason, @HeaderParam(HDR_COMMENT) final String comment, @javax.ws.rs.core.Context final HttpServletRequest request, @javax.ws.rs.core.Context final UriInfo uriInfo) throws AccountApiException {
    final NodeCommandMetadata metadata = toNodeCommandMetadata(json);
    final NodeCommand nodeCommand = new NodeCommand() {

        @Override
        public boolean isSystemCommandType() {
            return json.isSystemCommandType();
        }

        @Override
        public String getNodeCommandType() {
            return json.getNodeCommandType();
        }

        @Override
        public NodeCommandMetadata getNodeCommandMetadata() {
            return metadata;
        }
    };
    killbillInfoApi.triggerNodeCommand(nodeCommand, localNodeOnly);
    return Response.status(Status.CREATED).build();
}
Also used : NodeCommandMetadata(org.killbill.billing.util.nodes.NodeCommandMetadata) PluginNodeCommandMetadata(org.killbill.billing.util.nodes.PluginNodeCommandMetadata) NodeCommand(org.killbill.billing.util.nodes.NodeCommand) TimedResource(org.killbill.commons.metrics.TimedResource) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with NodeCommandMetadata

use of org.killbill.billing.util.nodes.NodeCommandMetadata in project killbill by killbill.

the class NodesInfoResource method toNodeCommandMetadata.

private NodeCommandMetadata toNodeCommandMetadata(final NodeCommandJson input) {
    if (input.getNodeCommandProperties() == null || input.getNodeCommandProperties().isEmpty()) {
        return new NodeCommandMetadata() {

            @Override
            public List<NodeCommandProperty> getProperties() {
                return ImmutableList.<NodeCommandProperty>of();
            }
        };
    }
    String pluginKey = null;
    String pluginName = null;
    String pluginVersion = null;
    final Iterator<NodeCommandPropertyJson> it = input.getNodeCommandProperties().iterator();
    while (it.hasNext()) {
        final NodeCommandProperty cur = it.next();
        if (PluginNodeCommandMetadata.PLUGIN_NAME.equals(cur.getKey())) {
            pluginName = (String) cur.getValue();
        } else if (PluginNodeCommandMetadata.PLUGIN_VERSION.equals(cur.getKey())) {
            pluginVersion = (String) cur.getValue();
        } else if (PluginNodeCommandMetadata.PLUGIN_KEY.equals(cur.getKey())) {
            pluginKey = (String) cur.getValue();
        }
        if (pluginName != null && pluginVersion != null && pluginKey != null) {
            break;
        }
    }
    if (pluginName != null || pluginKey != null) {
        removeFirstClassProperties(input.getNodeCommandProperties(), PluginNodeCommandMetadata.PLUGIN_NAME, PluginNodeCommandMetadata.PLUGIN_VERSION, PluginNodeCommandMetadata.PLUGIN_KEY);
        return new PluginNodeCommandMetadata(pluginKey, pluginName, pluginVersion, toNodeCommandProperties(input.getNodeCommandProperties()));
    } else {
        return new NodeCommandMetadata() {

            @Override
            public List<NodeCommandProperty> getProperties() {
                return toNodeCommandProperties(input.getNodeCommandProperties());
            }
        };
    }
}
Also used : NodeCommandPropertyJson(org.killbill.billing.jaxrs.json.NodeCommandPropertyJson) PluginNodeCommandMetadata(org.killbill.billing.util.nodes.PluginNodeCommandMetadata) NodeCommandMetadata(org.killbill.billing.util.nodes.NodeCommandMetadata) PluginNodeCommandMetadata(org.killbill.billing.util.nodes.PluginNodeCommandMetadata) NodeCommandProperty(org.killbill.billing.util.nodes.NodeCommandProperty)

Aggregations

NodeCommandMetadata (org.killbill.billing.util.nodes.NodeCommandMetadata)2 PluginNodeCommandMetadata (org.killbill.billing.util.nodes.PluginNodeCommandMetadata)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 NodeCommandPropertyJson (org.killbill.billing.jaxrs.json.NodeCommandPropertyJson)1 NodeCommand (org.killbill.billing.util.nodes.NodeCommand)1 NodeCommandProperty (org.killbill.billing.util.nodes.NodeCommandProperty)1 TimedResource (org.killbill.commons.metrics.TimedResource)1