Skip to content

Commit

Permalink
Container names made safely
Browse files Browse the repository at this point in the history
  • Loading branch information
smirnp committed Dec 13, 2018
1 parent ff8c853 commit f9421a3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Builder() {
containerName("rabbit");
imageName("rabbitmq:latest");
addPortBindings("5672/tcp", PortBinding.of("0.0.0.0", 5672));
useCachedContainer(true);
//useCachedContainer(true);
skipLogsReading(true);
addNetworks(HOBBIT_NETWORKS);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public PullBasedDockersBuilder(String imageName){
super(imageName);
super.imageName(imageName);
String[] splitted = imageName.split("/");
super.containerName(splitted[splitted.length-1]);
super.containerName(splitted[splitted.length-1].split(":")[0]);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void checkHealth(Boolean dockerize) throws Exception {
commandQueueListener.terminate();
componentsExecutor.shutdown();

//rabbitMqDockerizer.stop();
rabbitMqDockerizer.stop();

Assert.assertFalse(componentsExecutor.anyExceptions());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void receiveCommand(byte command, byte[] data) {
try {
commandReaction.handleCmd(command, data, replyTo);
} catch (Exception e) {
logger.error("Failed to handle command with {}: {}",commandReaction.toString(), e.getMessage());
logger.error("Failed to handle command with {}: {}",commandReaction.getClass().getSimpleName(), e.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,26 @@ public void handleCmd(Byte command, byte[] bytes, String replyTo) throws Excepti

logger.debug("CONTAINER_START command received with imageName="+startCommandData.image+"");

String containerId=null;
Component compToSubmit = null;
String containerId = null;

String[] splitted = startCommandData.getImage().split("/");
String cleanedImageName=splitted[splitted.length-1].split(":")[0];

if (benchmarkController!=null && startCommandData.image.equals(benchmarkControllerImageName)) {
compToSubmit = benchmarkController;
containerId = benchmarkControllerImageName;
containerId = cleanedImageName;
}else

if (dataGenerator!=null && startCommandData.image.equals(dataGeneratorImageName)) {
compToSubmit = dataGenerator;
containerId = dataGeneratorImageName+"_"+dataGeneratorsCount;
containerId = cleanedImageName+"_"+dataGeneratorsCount;
dataGeneratorsCount++;
}else

if(taskGenerator!=null && startCommandData.image.equals(taskGeneratorImageName)) {
compToSubmit = taskGenerator;
containerId = taskGeneratorImageName+"_"+taskGeneratorsCount;
containerId = cleanedImageName+"_"+taskGeneratorsCount;
// if(AbstractDockerizer.class.isInstance(taskGenerator)){
// compToSubmit = ((AbstractDockerizer)taskGenerator).clone(new ArrayList(Arrays.asList(startCommandData.environmentVariables)));
// containerId = ((AbstractDockerizer)compToSubmit).createContainerWithRemoveAllPrevs(startCommandData.environmentVariables);
Expand All @@ -111,50 +114,34 @@ public void handleCmd(Byte command, byte[] bytes, String replyTo) throws Excepti

if(evalStorage!=null && startCommandData.image.equals(evalStorageImageName)){
compToSubmit = evalStorage;
containerId = evalStorageImageName;
// if(AbstractDockerizer.class.isInstance(compToSubmit))
// containerId = ((AbstractDockerizer)compToSubmit).createContainerWithRemoveAllPrevs(startCommandData.environmentVariables);
// else
// containerId = evalStorageImageName;

containerId = cleanedImageName;
}else

if(evalModule!=null && startCommandData.image.equals(evalModuleImageName)) {
compToSubmit = evalModule;
containerId = evalModuleImageName;
// if(AbstractDockerizer.class.isInstance(compToSubmit))
// containerId = ((AbstractDockerizer)compToSubmit).createContainerWithRemoveAllPrevs(startCommandData.environmentVariables);
// else
// containerId = evalModuleImageName;
containerId = cleanedImageName;

}else

if(systemAdapter !=null && startCommandData.image.equals(systemAdapterImageName)) {
compToSubmit = systemAdapter;
containerId = systemAdapterImageName+"_"+systemContainersCount;
// if(AbstractDockerizer.class.isInstance(systemAdapter)){
// compToSubmit = ((AbstractDockerizer)systemAdapter).clone(new ArrayList(Arrays.asList(startCommandData.environmentVariables)));
// containerId = ((AbstractDockerizer)compToSubmit).createContainerWithRemoveAllPrevs(startCommandData.environmentVariables);
// }else {
// compToSubmit = systemAdapter.getClass().getConstructor().newInstance();
// containerId = systemAdapterImageName+"_"+systemContainersCount;
// }
//containerId = systemAdapterImageName+"_"+systemContainersCount;
containerId = cleanedImageName+"_"+systemContainersCount;
systemContainersCount++;
}else if(customContainers.containsKey(startCommandData.image)){
String imageName = startCommandData.image;
Component customComponent = customContainers.get(imageName);
int runningCustomContainersCount = (customContainersRunning.containsKey(imageName)? customContainersRunning.get(imageName) :0);

Component customComponent = customContainers.get(cleanedImageName);
int runningCustomContainersCount = (customContainersRunning.containsKey(cleanedImageName)? customContainersRunning.get(cleanedImageName) :0);

if(AbstractDockerizer.class.isInstance(customComponent)){
List<String> envVars = new ArrayList(Arrays.asList(startCommandData.environmentVariables));
compToSubmit = ((AbstractDockerizer)customComponent).clone(envVars);
containerId = ((AbstractDockerizer)compToSubmit).createContainerWithRemoveAllPrevs(envVars.toArray(new String[0]));
}else {
compToSubmit = customComponent.getClass().getConstructor().newInstance();
containerId = imageName+"_"+runningCustomContainersCount;
containerId = cleanedImageName+"_"+runningCustomContainersCount;
}
runningCustomContainersCount++;
customContainersRunning.put(imageName, runningCustomContainersCount);
customContainersRunning.put(cleanedImageName, runningCustomContainersCount);
}else{
String imgName = startCommandData.image;
if(!imgName.contains(":"))
Expand Down

0 comments on commit f9421a3

Please sign in to comment.