Search in sources :

Example 1 with NodeCommand

use of org.killbill.billing.util.nodes.NodeCommand 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 NodeCommand

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

the class TestWithFakeKPMPlugin method testPluginInstallMechanism.

@Test(groups = "slow")
public void testPluginInstallMechanism() throws Exception {
    final NodeCommand nodeCommand = new NodeCommand() {

        @Override
        public boolean isSystemCommandType() {
            return true;
        }

        @Override
        public String getNodeCommandType() {
            return SystemNodeCommandType.INSTALL_PLUGIN.name();
        }

        @Override
        public NodeCommandMetadata getNodeCommandMetadata() {
            return new PluginNodeCommandMetadata(NEW_PLUGIN_NAME, NEW_PLUGIN_NAME, NEW_PLUGIN_VERSION, ImmutableList.<NodeCommandProperty>of());
        }
    };
    busHandler.pushExpectedEvent(NextEvent.BROADCAST_SERVICE);
    nodesApi.triggerNodeCommand(nodeCommand, false);
    assertListenerStatus();
    // Exit condition is based on the new config being updated on disk
    await().atMost(3, SECONDS).until(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            final Iterable<NodeInfo> rawNodeInfos = nodesApi.getNodesInfo();
            final List<NodeInfo> nodeInfos = ImmutableList.<NodeInfo>copyOf(rawNodeInfos);
            Assert.assertEquals(nodeInfos.size(), 1);
            final NodeInfo nodeInfo = nodeInfos.get(0);
            final Iterable<PluginInfo> rawPluginInfos = nodeInfo.getPluginInfo();
            final List<PluginInfo> pluginsInfo = ImmutableList.copyOf(rawPluginInfos);
            if (pluginsInfo.size() == 1) {
                final PluginInfo pluginInfo = pluginsInfo.get(0);
                Assert.assertEquals(pluginInfo.getPluginName(), NEW_PLUGIN_NAME);
                Assert.assertEquals(pluginInfo.getVersion(), NEW_PLUGIN_VERSION);
            }
            return pluginsInfo.size() == 1;
        }
    });
}
Also used : PluginNodeCommandMetadata(org.killbill.billing.util.nodes.PluginNodeCommandMetadata) NodeInfo(org.killbill.billing.util.nodes.NodeInfo) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) PluginInfo(org.killbill.billing.osgi.api.PluginInfo) NodeCommand(org.killbill.billing.util.nodes.NodeCommand) PluginConfigException(org.killbill.billing.osgi.pluginconf.PluginConfigException) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Aggregations

NodeCommand (org.killbill.billing.util.nodes.NodeCommand)2 PluginNodeCommandMetadata (org.killbill.billing.util.nodes.PluginNodeCommandMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 PluginInfo (org.killbill.billing.osgi.api.PluginInfo)1 PluginConfigException (org.killbill.billing.osgi.pluginconf.PluginConfigException)1 NodeCommandMetadata (org.killbill.billing.util.nodes.NodeCommandMetadata)1 NodeInfo (org.killbill.billing.util.nodes.NodeInfo)1 TimedResource (org.killbill.commons.metrics.TimedResource)1 Test (org.testng.annotations.Test)1