Search in sources :

Example 1 with PluginNodeCommandMetadata

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

Example 2 with PluginNodeCommandMetadata

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

PluginNodeCommandMetadata (org.killbill.billing.util.nodes.PluginNodeCommandMetadata)2 ImmutableList (com.google.common.collect.ImmutableList)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 NodeCommandPropertyJson (org.killbill.billing.jaxrs.json.NodeCommandPropertyJson)1 PluginInfo (org.killbill.billing.osgi.api.PluginInfo)1 PluginConfigException (org.killbill.billing.osgi.pluginconf.PluginConfigException)1 NodeCommand (org.killbill.billing.util.nodes.NodeCommand)1 NodeCommandMetadata (org.killbill.billing.util.nodes.NodeCommandMetadata)1 NodeCommandProperty (org.killbill.billing.util.nodes.NodeCommandProperty)1 NodeInfo (org.killbill.billing.util.nodes.NodeInfo)1 Test (org.testng.annotations.Test)1