diff --git a/pom.xml b/pom.xml
index 9831192..e4f6daa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -23,6 +23,7 @@
core
1.0.15
+
diff --git a/src/main/java/org/hobbit/core/Commands.java b/src/main/java/org/hobbit/core/Commands.java
index c4b2e76..800f3f6 100644
--- a/src/main/java/org/hobbit/core/Commands.java
+++ b/src/main/java/org/hobbit/core/Commands.java
@@ -98,6 +98,8 @@ private Commands() {
public static final byte REQUEST_SYSTEM_RESOURCES_USAGE = 18;
+ public static final byte EXECUTE_ASYNC_COMMAND = 19;
+
private static final ImmutableMap ID_TO_COMMAND_NAME_MAP = generateMap();
private static ImmutableMap generateMap() {
diff --git a/src/main/java/org/hobbit/core/components/AbstractCommandReceivingComponent.java b/src/main/java/org/hobbit/core/components/AbstractCommandReceivingComponent.java
index 2a3ec1d..5c0a3bd 100644
--- a/src/main/java/org/hobbit/core/components/AbstractCommandReceivingComponent.java
+++ b/src/main/java/org/hobbit/core/components/AbstractCommandReceivingComponent.java
@@ -27,6 +27,7 @@
import org.apache.commons.io.IOUtils;
import org.hobbit.core.Commands;
import org.hobbit.core.Constants;
+import org.hobbit.core.data.ExecuteCommandData;
import org.hobbit.core.data.StartCommandData;
import org.hobbit.core.data.StopCommandData;
import org.hobbit.core.rabbit.RabbitMQUtils;
@@ -60,11 +61,13 @@ public abstract class AbstractCommandReceivingComponent extends AbstractComponen
* sent via the command queue and for which an answer is expected.
*/
private String responseQueueName = null;
+ //private String responseQueueName2 = null;
/**
* Consumer of the queue that is used to receive responses for messages that
* are sent via the command queue and for which an answer is expected.
*/
private QueueingConsumer responseConsumer = null;
+ //private QueueingConsumer responseConsumer2 = null;
/**
* Factory for generating queues with which the commands are sent and
* received. It is separated from the data connections since otherwise the
@@ -306,6 +309,16 @@ private void initResponseQueue() throws IOException {
}
}
+// private void initResponseQueue2() throws IOException {
+// if (responseQueueName2 == null) {
+// responseQueueName2 = cmdChannel.queueDeclare().getQueue();
+// }
+// if (responseConsumer2 == null) {
+// responseConsumer2 = new QueueingConsumer(cmdChannel);
+// cmdChannel.basicConsume(responseQueueName2, responseConsumer2);
+// }
+// }
+
/**
* @return the cmdResponseTimeout
*/
@@ -320,6 +333,34 @@ public void setCmdResponseTimeout(long cmdResponseTimeout) {
this.cmdResponseTimeout = cmdResponseTimeout;
}
+ /**
+ * This executes command against running container.
+ * This functionality must be enabled by platform administrator
+ *
+ * @param containerId
+ * the name of the container instance that should be stopped
+ */
+ protected boolean execAsyncCommand(String containerId, String[] command) {
+ try {
+ initResponseQueue();
+ byte data[] = RabbitMQUtils.writeString(
+ gson.toJson(new ExecuteCommandData(containerId, command)));
+ BasicProperties props = new BasicProperties.Builder().deliveryMode(2).replyTo(responseQueueName).build();
+ sendToCmdQueue(Commands.EXECUTE_ASYNC_COMMAND, data, props);
+ QueueingConsumer.Delivery delivery = responseConsumer.nextDelivery(cmdResponseTimeout*2);
+ Objects.requireNonNull(delivery, "Didn't got a response for a create container message.");
+ if (delivery.getBody().length > 0){
+ if(RabbitMQUtils.readString(delivery.getBody()).equals("Succeeded"))
+ return true;
+ }
+
+
+ } catch (Exception e) {
+ LOGGER.error("Got exception while trying to execute command for the container of the \"" + containerId+ "\" image.", e);
+ }
+ return false;
+ }
+
@Override
public void close() throws IOException {
if (cmdChannel != null) {
diff --git a/src/main/java/org/hobbit/core/components/AbstractPlatformConnectorComponent.java b/src/main/java/org/hobbit/core/components/AbstractPlatformConnectorComponent.java
index 896da49..ef6e498 100644
--- a/src/main/java/org/hobbit/core/components/AbstractPlatformConnectorComponent.java
+++ b/src/main/java/org/hobbit/core/components/AbstractPlatformConnectorComponent.java
@@ -78,6 +78,12 @@ protected void addContainerObserver(String containerName, ContainerStateObserver
}
}
+ @Override
+ public boolean execAsyncCommand(String containerId, String[] command) {
+ return super.execAsyncCommand(containerId, command);
+ }
+
+
@Override
public RabbitQueueFactory getFactoryForIncomingCmdQueues() {
return cmdQueueFactory;
diff --git a/src/main/java/org/hobbit/core/components/PlatformConnector.java b/src/main/java/org/hobbit/core/components/PlatformConnector.java
index 9e637e0..7d8d0f6 100644
--- a/src/main/java/org/hobbit/core/components/PlatformConnector.java
+++ b/src/main/java/org/hobbit/core/components/PlatformConnector.java
@@ -58,4 +58,6 @@ public interface PlatformConnector {
public RabbitQueueFactory getFactoryForIncomingDataQueues();
public RabbitQueueFactory getFactoryForOutgoingCmdQueues();
public RabbitQueueFactory getFactoryForIncomingCmdQueues();
+
+ public boolean execAsyncCommand(String containerId, String[] command);
}
diff --git a/src/main/java/org/hobbit/core/data/ExecuteCommandData.java b/src/main/java/org/hobbit/core/data/ExecuteCommandData.java
new file mode 100644
index 0000000..cc1b3d1
--- /dev/null
+++ b/src/main/java/org/hobbit/core/data/ExecuteCommandData.java
@@ -0,0 +1,56 @@
+package org.hobbit.core.data;
+
+/**
+ * @author Pavel Smirnov. (psmirnov@agtinternational.com / smirnp@gmail.com)
+ */
+/**
+ * This file is part of core.
+ *
+ * core is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * core is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with core. If not, see .
+ */
+
+public class ExecuteCommandData {
+
+ public String containerId;
+ public String[] command;
+
+ public ExecuteCommandData(String containerId, String[] command) {
+ this.containerId = containerId;
+ this.command = command;
+ }
+
+ public String getContainerId() {
+ return containerId;
+ }
+
+ public void setContainerId(String value) { this.containerId = value; }
+
+ public String[] getCommand() {
+ return command;
+ }
+
+ public void setCommand(String[] value) { this.command = value; }
+
+
+ @Override
+ public String toString() {
+ StringBuilder builder = new StringBuilder();
+ builder.append("ExecuteCommandData [containerId=");
+ builder.append(containerId);
+ builder.append(", command=");
+ builder.append(command);
+ builder.append("]");
+ return builder.toString();
+ }
+}