Skip to content
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

ContainerCommandsReaction creates custom containers twice #8

Open
bushranz opened this issue May 11, 2019 · 2 comments
Open

ContainerCommandsReaction creates custom containers twice #8

bushranz opened this issue May 11, 2019 · 2 comments

Comments

@bushranz
Copy link

public void handleCmd(Byte command, byte[] bytes, String replyTo) throws Exception {
      ......
            } else if(this.customContainers.containsKey(e)) {
                Component e1 = (Component)this.customContainers.get(e);
                int runningCustomContainersCount = this.customContainersRunning.containsKey(e)?((Integer)this.customContainersRunning.get(e)).intValue():0;
                if(AbstractDockerizer.class.isInstance(e1)) {
                    ArrayList envVars = new ArrayList(Arrays.asList(buffer.environmentVariables));
                    commandToSend = ((AbstractDockerizer)e1).clone(envVars);
                    containerName = ((AbstractDockerizer)commandToSend).createContainerWithRemoveAllPrevs((String[])envVars.toArray(new String[0]));
                } else {
                    commandToSend = (Component)e1.getClass().getConstructor(new Class[0]).newInstance(new Object[0]);
                    containerName = e + "_" + runningCustomContainersCount;
                }

                ++runningCustomContainersCount;
                this.customContainersRunning.put(e, Integer.valueOf(runningCustomContainersCount));
            } 
........
            }
            if(commandToSend != null) {
                if(AbstractDockerizer.class.isInstance(commandToSend)) {
                    commandToSend = ((AbstractDockerizer)commandToSend).clone(new ArrayList(Arrays.asList(buffer.environmentVariables)));
                    containerName = ((AbstractDockerizer)commandToSend).createContainerWithRemoveAllPrevs(buffer.environmentVariables);
                } else {
                    commandToSend = (Component)commandToSend.getClass().getConstructor(new Class[0]).newInstance(new Object[0]);
                }
.....
}

When the component to create is a custom component, the method to create the component is called twice (for both cases: if it is instance of AbstractDockerizer or java component ). First, component is created when this condition is true
else if(this.customContainers.containsKey(e)) { ....

And then again, inside the next condition:
else if(this.customContainers.containsKey(e)) {...

Though the createContainerWithRemoveAllPrevs() removes the containers with the same name first, so the right number of containers are created. But when there are a lot of containers are to be created with image sizes (like in my usecase), then it takes double the time to create those components.

@smirnp
Copy link
Member

smirnp commented May 13, 2019

Thank you for pointing that out. I have fixed and updated the master. Please check if it works

@bushranz
Copy link
Author

Thank You. As a workout last month, I fixed it in my local copy of the class. But I will let you know when I run again with the updated master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants