Skip to content

Component creation transparency #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: pg-merge
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/org/hobbit/core/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,6 @@ private Constants() {

public static final TimeZone DEFAULT_TIME_ZONE = TimeZone.getTimeZone("GMT");

public static final String RABBIT_CONTAINER_SERVICE = "RABBIT_CONTAINER_SERVICE";

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import org.apache.jena.vocabulary.RDF;
import org.hobbit.core.Commands;
import org.hobbit.core.Constants;
import org.hobbit.core.containerservice.ContainerCreation;
import org.hobbit.core.containerservice.ContainerCreationFactory;
import org.hobbit.core.containerservice.RabbitMQContainerCreator;
import org.hobbit.core.rabbit.RabbitMQUtils;
import org.hobbit.vocab.HOBBIT;
import org.hobbit.vocab.HobbitErrors;
Expand Down Expand Up @@ -134,6 +137,10 @@ public abstract class AbstractBenchmarkController extends AbstractPlatformConnec
* The URI of the experiment.
*/
protected String experimentUri;
/**
* The instance to create container
*/
protected ContainerCreation containerCreation;

/**
* Constructor.
Expand All @@ -145,6 +152,7 @@ public AbstractBenchmarkController() {
@Override
public void init() throws Exception {
super.init();
containerCreation = ContainerCreationFactory.getContainerCreationObject(EnvVariables.getString(Constants.RABBIT_CONTAINER_SERVICE, LOGGER), this);
// benchmark controllers should be able to accept broadcasts
addCommandHeaderId(Constants.HOBBIT_SESSION_ID_FOR_BROADCASTS);

Expand Down Expand Up @@ -175,9 +183,9 @@ public void run() throws Exception {
* @param envVariables
* environment variables for the data generators
*/
protected void createDataGenerators(String dataGeneratorImageName, int numberOfDataGenerators,
protected Set<String> createDataGenerators(String dataGeneratorImageName, int numberOfDataGenerators,
String[] envVariables) {
createGenerator(dataGeneratorImageName, numberOfDataGenerators, envVariables, dataGenContainerIds);
return createGenerator(dataGeneratorImageName, numberOfDataGenerators, envVariables);
}

/**
Expand All @@ -191,9 +199,9 @@ protected void createDataGenerators(String dataGeneratorImageName, int numberOfD
* @param envVariables
* environment variables for the task generators
*/
protected void createTaskGenerators(String taskGeneratorImageName, int numberOfTaskGenerators,
protected Set<String> createTaskGenerators(String taskGeneratorImageName, int numberOfTaskGenerators,
String[] envVariables) {
createGenerator(taskGeneratorImageName, numberOfTaskGenerators, envVariables, taskGenContainerIds);
return createGenerator(taskGeneratorImageName, numberOfTaskGenerators, envVariables);
}

/**
Expand All @@ -208,8 +216,8 @@ protected void createTaskGenerators(String taskGeneratorImageName, int numberOfT
* @param generatorIds
* set of generator container names
*/
private void createGenerator(String generatorImageName, int numberOfGenerators, String[] envVariables,
Set<String> generatorIds) {
public Set<String> createGenerator(String generatorImageName, int numberOfGenerators, String[] envVariables) {
Set<String> generatorIds = new HashSet<>();
String containerId;
String variables[] = envVariables != null ? Arrays.copyOf(envVariables, envVariables.length + 2)
: new String[2];
Expand All @@ -228,6 +236,7 @@ private void createGenerator(String generatorImageName, int numberOfGenerators,
throw new IllegalStateException(errorMsg);
}
}
return generatorIds;
}

/**
Expand Down Expand Up @@ -611,4 +620,23 @@ protected void containerCrashed(String containerName) {
sendResultModel(resultModel);
System.exit(1);
}

public Set<String> getDataGenContainerIds() {
return dataGenContainerIds;
}

public Set<String> getTaskGenContainerIds() {
return taskGenContainerIds;
}

public String getEvalStoreContainerId() {
return evalStoreContainerId;
}

public void setEvalStoreContainerId(String evalStoreContainerId) {
this.evalStoreContainerId = evalStoreContainerId;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public abstract class AbstractCommandReceivingComponent extends AbstractComponen
* Name 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 String responseQueueName = null;
protected String responseQueueName = null;
/**
* Mapping of RabbitMQ's correlationIDs to Future objects corresponding
* to that RPC call.
*/
private Map<String, SettableFuture<String>> responseFutures = Collections.synchronizedMap(new LinkedHashMap<>());
protected Map<String, SettableFuture<String>> responseFutures = Collections.synchronizedMap(new LinkedHashMap<>());
/**
* 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.
Expand Down Expand Up @@ -304,7 +304,7 @@ protected String createContainer(String imageName, String[] envVariables) {
* user-provided array of environment variables
* @return the extended array of environment variables
*/
protected String[] extendContainerEnvVariables(String[] envVariables) {
public String[] extendContainerEnvVariables(String[] envVariables) {
if (envVariables == null) {
envVariables = new String[0];
}
Expand Down Expand Up @@ -347,7 +347,7 @@ protected String[] extendContainerEnvVariables(String[] envVariables) {
* container
* @return the name of the container instance or null if an error occurred
*/
protected String createContainer(String imageName, String containerType, String[] envVariables) {
public String createContainer(String imageName, String containerType, String[] envVariables) {
return createContainer(imageName, containerType, envVariables, null);
}

Expand Down Expand Up @@ -474,7 +474,15 @@ protected Future<String> createContainerAsync(String imageName, String container
return null;
}

/**
public Map<String, SettableFuture<String>> getResponseFutures() {
return responseFutures;
}

public String getResponseQueueName() {
return responseQueueName;
}

/**
* This method sends a {@link Commands#DOCKER_CONTAINER_STOP} command to
* stop the container with the given id.
*
Expand All @@ -497,7 +505,7 @@ protected void stopContainer(String containerName) {
* @throws IOException
* if a communication problem occurs
*/
private void initResponseQueue() throws IOException {
public void initResponseQueue() throws IOException {
if (responseQueueName == null) {
responseQueueName = cmdChannel.queueDeclare().getQueue();
}
Expand Down Expand Up @@ -567,5 +575,24 @@ public void close() throws IOException {
}
super.close();
}

public String getContainerName() {
return containerName;
}

public void setContainerName(String containerName) {
this.containerName = containerName;
}

public Gson getGson() {
return gson;
}

public void setGson(Gson gson) {
this.gson = gson;
}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.hobbit.core.components;

import com.rabbitmq.client.AMQP;

public abstract class AbstractPlatformController extends AbstractCommandReceivingComponent{

public AbstractPlatformController() {
super();
}

public AbstractPlatformController(boolean execCommandsInParallel) {
super(execCommandsInParallel);
}

public abstract void createComponent(byte command, byte[] data, String sessionId, AMQP.BasicProperties props);

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import java.io.IOException;
import java.util.concurrent.Semaphore;

import org.apache.commons.io.IOUtils;
import org.hobbit.core.Commands;
import org.hobbit.core.Constants;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.hobbit.core.containerservice;

import java.util.Set;
import org.hobbit.core.components.AbstractPlatformController;

/**
* This interface provides methods that provides functionalities
* to create {@link DirectContainerCreator} or {@link RabbitMQContainerCreator}
*
* @author Altafhusen Makandar
* @author Sourabh Poddar
* @author Yamini Punetha
* @author Melissa Das
*
*/
public interface ContainerCreation {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add javadoc comments to all methods of this interface.


/**
* Creates the given number of data generators using the given image name
* and environment variables.
*
* @param dataGeneratorImageName
* name of the data generator Docker image
* @param numberOfDataGenerators
* number of generators that should be created
* @param envVariables
* environment variables for the data generators
*/
Set<String> createDataGenerators(String dataGeneratorImageName, int numberOfDataGenerators,
String[] envVariables, AbstractPlatformController dummyComponent);

/**
* Creates the given number of task generators using the given image name
* and environment variables.
*
* @param taskGeneratorImageName
* name of the task generator Docker image
* @param numberOfTaskGenerators
* number of generators that should be created
* @param envVariables
* environment variables for the task generators
*/
Set<String> createTaskGenerators(String taskGeneratorImageName, int numberOfTaskGenerators,
String[] envVariables, AbstractPlatformController dummyComponent);

/**
* Creates the evaluate storage using the given image name and environment
* variables.
*
* @param evalStorageImageName
* name of the evaluation storage image
* @param envVariables
* environment variables that should be given to the component
*/
String createEvaluationStorage(String evalStorageImageName, String[] envVariables,
AbstractPlatformController dummyComponent);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.hobbit.core.containerservice;

import org.hobbit.core.Constants;
import org.hobbit.core.components.AbstractBenchmarkController;

/**
* This class provides functionality to obtain an instance of {@link ContainerCreation}
*
* @author Altafhusen Makandar
* @author Sourabh Poddar
* @author Yamini Punetha
* @author Melissa Das
*
*/
public class ContainerCreationFactory {

/**
* This static method returns the instance of {@link RabbitMQContainerCreator} or {@link DirectContainerCreator}
* based on the value of the environment variable {@link Constants#RABBIT_CONTAINER_SERVICE}
*
* @param isRabbitContainerService
* the environment variable that decides which instance of {@link ContainerCreation} will be returned.
* @param abstractBenchmarkController
* instance of {@link AbstractBenchmarkController}
* @return an instance of {@link RabbitMQContainerCreator} or {@link DirectContainerCreator}
*/
public static ContainerCreation getContainerCreationObject(String isRabbitContainerService, AbstractBenchmarkController abstractBenchmarkController) {
if(isRabbitContainerService.equals("true")) {
return new RabbitMQContainerCreator(abstractBenchmarkController);
}
return new DirectContainerCreator(abstractBenchmarkController);
}

}
Loading