Commit 6e809dd2 authored by Joerg Domaschka's avatar Joerg Domaschka

fixed bug in transition handler. container creation invoked twice.

parent 9d493075
package de.uniulm.omi.cloudiator.lance.container.standard;
import java.util.Arrays;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerStatus;
import de.uniulm.omi.cloudiator.lance.lca.registry.RegistrationException;
import de.uniulm.omi.cloudiator.lance.util.state.ErrorAwareTransitionBuilder;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionAction;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionException;
final class BootstrapTransitionAction implements TransitionAction {
private final ErrorAwareContainer<?> theContainer;
BootstrapTransitionAction(ErrorAwareContainer<?> container) {
theContainer = container;
}
@Override
public void transit(Object[] params) throws TransitionException {
try {
checkForBootstrapParameters(params);
theContainer.logic.doInit(null);
theContainer.postBootstrapAction();
theContainer.registerStatus(ContainerStatus.BOOTSTRAPPED);
} catch (ContainerException | RegistrationException ce) {
ErrorAwareContainer.getLogger().error("could not initialise container", ce);
throw new TransitionException(ce);
}
}
static void checkForBootstrapParameters(Object[] o){
//if(o == null || o.length == 0 || o.length > 1 || !(o[0] instanceof OperatingSystem)) throw new IllegalArgumentException(Arrays.toString(o));
if(o == null || o.length > 0)
throw new IllegalArgumentException(Arrays.toString(o));
// return (OperatingSystem) o[0];
return;
}
public static void create(ErrorAwareTransitionBuilder<ContainerStatus> transitionBuilder,
ErrorAwareContainer<?> container) {
CreateTransitionAction action = new CreateTransitionAction(container);
// FIXME: add error handler //
transitionBuilder.setStartState(ContainerStatus.CREATED).
setIntermediateState(ContainerStatus.BOOTSTRAPPING, false).
setEndState(ContainerStatus.BOOTSTRAPPED).
setErrorState(ContainerStatus.BOOTSTRAPPING_FAILED).
addTransitionAction(action);
transitionBuilder.buildAndRegister();
}
public static boolean isSuccessfullEndState(ContainerStatus stat) {
return stat == ContainerStatus.BOOTSTRAPPED;
}
public static boolean isKnownErrorState(ContainerStatus stat) {
return stat == ContainerStatus.BOOTSTRAPPING_FAILED;
}
}
package de.uniulm.omi.cloudiator.lance.container.standard;
import java.util.Arrays;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerStatus;
import de.uniulm.omi.cloudiator.lance.lca.registry.RegistrationException;
import de.uniulm.omi.cloudiator.lance.util.state.ErrorAwareTransitionBuilder;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionAction;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionException;
final class BootstrapTransitionAction implements TransitionAction {
private final ErrorAwareContainer<?> theContainer;
private BootstrapTransitionAction(ErrorAwareContainer<?> container) {
theContainer = container;
}
@Override
public void transit(Object[] params) throws TransitionException {
try {
checkForBootstrapParameters(params);
theContainer.logic.doInit(null);
theContainer.postBootstrapAction();
theContainer.registerStatus(ContainerStatus.BOOTSTRAPPED);
} catch (ContainerException | RegistrationException ce) {
ErrorAwareContainer.getLogger().error("could not initialise container", ce);
throw new TransitionException(ce);
}
}
static void checkForBootstrapParameters(Object[] o){
//if(o == null || o.length == 0 || o.length > 1 || !(o[0] instanceof OperatingSystem)) throw new IllegalArgumentException(Arrays.toString(o));
if(o == null || o.length > 0)
throw new IllegalArgumentException(Arrays.toString(o));
// return (OperatingSystem) o[0];
return;
}
public static void create(ErrorAwareTransitionBuilder<ContainerStatus> transitionBuilder,
ErrorAwareContainer<?> container) {
BootstrapTransitionAction action = new BootstrapTransitionAction(container);
// FIXME: add error handler //
transitionBuilder.setStartState(ContainerStatus.CREATED).
setIntermediateState(ContainerStatus.BOOTSTRAPPING, false).
setEndState(ContainerStatus.BOOTSTRAPPED).
setErrorState(ContainerStatus.BOOTSTRAPPING_FAILED).
addTransitionAction(action);
transitionBuilder.buildAndRegister();
}
public static boolean isSuccessfullEndState(ContainerStatus stat) {
return stat == ContainerStatus.BOOTSTRAPPED;
}
public static boolean isKnownErrorState(ContainerStatus stat) {
return stat == ContainerStatus.BOOTSTRAPPING_FAILED;
}
}
package de.uniulm.omi.cloudiator.lance.container.standard;
import java.util.Arrays;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerStatus;
import de.uniulm.omi.cloudiator.lance.lca.registry.RegistrationException;
import de.uniulm.omi.cloudiator.lance.util.state.ErrorAwareTransitionBuilder;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionAction;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionException;
final class CreateTransitionAction implements TransitionAction {
private final ErrorAwareContainer<?> theContainer;
CreateTransitionAction(ErrorAwareContainer<?> container) {
theContainer = container;
}
@Override
public void transit(Object[] params) throws TransitionException {
try {
theContainer.preCreateAction();
checkForCreationParameters(params);
theContainer.logic.doCreate();
theContainer.postCreateAction();
theContainer.registerStatus(ContainerStatus.CREATED);
} catch (ContainerException | RegistrationException ce) {
throw new TransitionException(ce);
}
}
private static void checkForCreationParameters(Object[] o){
//if(o == null || o.length == 0 || o.length > 1 || !(o[0] instanceof OperatingSystem)) throw new IllegalArgumentException(Arrays.toString(o));
if(o == null || o.length > 0)
throw new IllegalArgumentException(Arrays.toString(o));
// return (OperatingSystem) o[0];
return;
}
public static void create(ErrorAwareTransitionBuilder<ContainerStatus> transitionBuilder,
ErrorAwareContainer<?> container) {
CreateTransitionAction action = new CreateTransitionAction(container);
// FIXME: add error handler //
transitionBuilder.setStartState(ContainerStatus.NEW).
setIntermediateState(ContainerStatus.CREATING, false).
setEndState(ContainerStatus.CREATED).
setErrorState(ContainerStatus.CREATION_FAILED).
addTransitionAction(action);
transitionBuilder.buildAndRegister();
}
public static boolean isSuccessfullEndState(ContainerStatus stat) {
return stat == ContainerStatus.CREATED;
}
public static boolean isKnownErrorState(ContainerStatus stat) {
return stat == ContainerStatus.CREATION_FAILED;
}
}
package de.uniulm.omi.cloudiator.lance.container.standard;
import java.util.Arrays;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerStatus;
import de.uniulm.omi.cloudiator.lance.lca.registry.RegistrationException;
import de.uniulm.omi.cloudiator.lance.util.state.ErrorAwareTransitionBuilder;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionAction;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionException;
final class CreateTransitionAction implements TransitionAction {
private final ErrorAwareContainer<?> theContainer;
private CreateTransitionAction(ErrorAwareContainer<?> container) {
theContainer = container;
}
@Override
public void transit(Object[] params) throws TransitionException {
try {
theContainer.preCreateAction();
checkForCreationParameters(params);
theContainer.logic.doCreate();
theContainer.postCreateAction();
theContainer.registerStatus(ContainerStatus.CREATED);
} catch (ContainerException | RegistrationException ce) {
throw new TransitionException(ce);
}
}
private static void checkForCreationParameters(Object[] o){
//if(o == null || o.length == 0 || o.length > 1 || !(o[0] instanceof OperatingSystem)) throw new IllegalArgumentException(Arrays.toString(o));
if(o == null || o.length > 0)
throw new IllegalArgumentException(Arrays.toString(o));
// return (OperatingSystem) o[0];
return;
}
public static void create(ErrorAwareTransitionBuilder<ContainerStatus> transitionBuilder,
ErrorAwareContainer<?> container) {
CreateTransitionAction action = new CreateTransitionAction(container);
// FIXME: add error handler //
transitionBuilder.setStartState(ContainerStatus.NEW).
setIntermediateState(ContainerStatus.CREATING, false).
setEndState(ContainerStatus.CREATED).
setErrorState(ContainerStatus.CREATION_FAILED).
addTransitionAction(action);
transitionBuilder.buildAndRegister();
}
public static boolean isSuccessfullEndState(ContainerStatus stat) {
return stat == ContainerStatus.CREATED;
}
public static boolean isKnownErrorState(ContainerStatus stat) {
return stat == ContainerStatus.CREATION_FAILED;
}
}
package de.uniulm.omi.cloudiator.lance.container.standard;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerStatus;
import de.uniulm.omi.cloudiator.lance.lca.registry.RegistrationException;
import de.uniulm.omi.cloudiator.lance.util.state.ErrorAwareTransitionBuilder;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionAction;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionException;
final class DestroyTransitionAction implements TransitionAction {
private final ErrorAwareContainer<?> theContainer;
DestroyTransitionAction(ErrorAwareContainer<?> container) {
theContainer = container;
}
@Override
public void transit(Object[] params) throws TransitionException {
theContainer.network.stopPortUpdaters();
try {
boolean forceShutdown = false;
try {
theContainer.preDestroyAction();
} catch (Exception ex) {
ErrorAwareContainer.getLogger().error("could not shut down component; trying to force shut down of container", ex);
forceShutdown = true;
}
theContainer.logic.doDestroy(forceShutdown);
theContainer.registerStatus(ContainerStatus.DESTROYED);
} catch (ContainerException | RegistrationException ce) {
ErrorAwareContainer.getLogger().error("could not shut down container;", ce);
throw new TransitionException(ce);
} finally {
try {
theContainer.setNetworking();
} catch (ContainerException e) {
ErrorAwareContainer.getLogger().error("could not update networking", e);
}
try {
theContainer.network.publishLocalData(theContainer.containerId);
} catch (ContainerException e) {
ErrorAwareContainer.getLogger().error("could not publish local data", e);
}
}
}
static void create(ErrorAwareTransitionBuilder<ContainerStatus> transitionBuilder,
ErrorAwareContainer<?> container) {
DestroyTransitionAction action = new DestroyTransitionAction(container);
// FIXME: add error handler //
transitionBuilder.setStartState(ContainerStatus.READY).
setIntermediateState(ContainerStatus.SHUTTING_DOWN, false).
setEndState(ContainerStatus.DESTROYED).
setErrorState(ContainerStatus.UNKNOWN).
addTransitionAction(action);
transitionBuilder.buildAndRegister();
}
public static boolean isKnownErrorState(ContainerStatus stat) {
return stat == ContainerStatus.UNKNOWN;
}
public static boolean isSuccessfullEndState(ContainerStatus stat) {
return stat == ContainerStatus.DESTROYED;
}
}
package de.uniulm.omi.cloudiator.lance.container.standard;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerStatus;
import de.uniulm.omi.cloudiator.lance.lca.registry.RegistrationException;
import de.uniulm.omi.cloudiator.lance.util.state.ErrorAwareTransitionBuilder;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionAction;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionException;
final class DestroyTransitionAction implements TransitionAction {
private final ErrorAwareContainer<?> theContainer;
private DestroyTransitionAction(ErrorAwareContainer<?> container) {
theContainer = container;
}
@Override
public void transit(Object[] params) throws TransitionException {
theContainer.network.stopPortUpdaters();
try {
boolean forceShutdown = false;
try {
theContainer.preDestroyAction();
} catch (Exception ex) {
ErrorAwareContainer.getLogger().error("could not shut down component; trying to force shut down of container", ex);
forceShutdown = true;
}
theContainer.logic.doDestroy(forceShutdown);
theContainer.registerStatus(ContainerStatus.DESTROYED);
} catch (ContainerException | RegistrationException ce) {
ErrorAwareContainer.getLogger().error("could not shut down container;", ce);
throw new TransitionException(ce);
} finally {
try {
theContainer.setNetworking();
} catch (ContainerException e) {
ErrorAwareContainer.getLogger().error("could not update networking", e);
}
try {
theContainer.network.publishLocalData(theContainer.containerId);
} catch (ContainerException e) {
ErrorAwareContainer.getLogger().error("could not publish local data", e);
}
}
}
static void create(ErrorAwareTransitionBuilder<ContainerStatus> transitionBuilder,
ErrorAwareContainer<?> container) {
DestroyTransitionAction action = new DestroyTransitionAction(container);
// FIXME: add error handler //
transitionBuilder.setStartState(ContainerStatus.READY).
setIntermediateState(ContainerStatus.SHUTTING_DOWN, false).
setEndState(ContainerStatus.DESTROYED).
setErrorState(ContainerStatus.UNKNOWN).
addTransitionAction(action);
transitionBuilder.buildAndRegister();
}
public static boolean isKnownErrorState(ContainerStatus stat) {
return stat == ContainerStatus.UNKNOWN;
}
public static boolean isSuccessfullEndState(ContainerStatus stat) {
return stat == ContainerStatus.DESTROYED;
}
}
package de.uniulm.omi.cloudiator.lance.container.standard;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerStatus;
import de.uniulm.omi.cloudiator.lance.lca.registry.RegistrationException;
import de.uniulm.omi.cloudiator.lance.lifecycle.LifecycleException;
import de.uniulm.omi.cloudiator.lance.util.state.ErrorAwareTransitionBuilder;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionAction;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionException;
final class InitTransitionAction implements TransitionAction {
private final ErrorAwareContainer<?> theContainer;
InitTransitionAction(ErrorAwareContainer<?> container) {
theContainer = container;
}
@Override
public void transit(Object[] params) throws TransitionException {
// FIXME: add code for starting from snapshot (skip init and install steps)
// probably has to be realised at a different place
try {
theContainer.preInitAction();
theContainer.logic.completeInit();
theContainer.postInitAction();
theContainer.registerStatus(ContainerStatus.READY);
} catch (ContainerException | LifecycleException | RegistrationException ce) {
ErrorAwareContainer.getLogger().error("could not initialise container;", ce);
}
}
public static void create(ErrorAwareTransitionBuilder<ContainerStatus> transitionBuilder,
ErrorAwareContainer<?> container) {
InitTransitionAction action = new InitTransitionAction(container);
// FIXME: add error handler //
transitionBuilder.setStartState(ContainerStatus.BOOTSTRAPPED).
setIntermediateState(ContainerStatus.INITIALISING, false).
setEndState(ContainerStatus.READY).
setErrorState(ContainerStatus.INITIALISATION_FAILED).
addTransitionAction(action);
transitionBuilder.buildAndRegister();
}
public static boolean isKnownErrorState(ContainerStatus stat) {
return stat == ContainerStatus.INITIALISATION_FAILED;
}
public static boolean isSuccessfullEndState(ContainerStatus stat) {
return stat == ContainerStatus.READY;
}
}
package de.uniulm.omi.cloudiator.lance.container.standard;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerStatus;
import de.uniulm.omi.cloudiator.lance.lca.registry.RegistrationException;
import de.uniulm.omi.cloudiator.lance.lifecycle.LifecycleException;
import de.uniulm.omi.cloudiator.lance.util.state.ErrorAwareTransitionBuilder;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionAction;
import de.uniulm.omi.cloudiator.lance.util.state.TransitionException;
final class InitTransitionAction implements TransitionAction {
private final ErrorAwareContainer<?> theContainer;
private InitTransitionAction(ErrorAwareContainer<?> container) {
theContainer = container;
}
@Override
public void transit(Object[] params) throws TransitionException {
// FIXME: add code for starting from snapshot (skip init and install steps)
// probably has to be realised at a different place
try {
theContainer.preInitAction();
theContainer.logic.completeInit();
theContainer.postInitAction();
theContainer.registerStatus(ContainerStatus.READY);
} catch (ContainerException | LifecycleException | RegistrationException ce) {
ErrorAwareContainer.getLogger().error("could not initialise container;", ce);
}
}
public static void create(ErrorAwareTransitionBuilder<ContainerStatus> transitionBuilder,
ErrorAwareContainer<?> container) {
InitTransitionAction action = new InitTransitionAction(container);
// FIXME: add error handler //
transitionBuilder.setStartState(ContainerStatus.BOOTSTRAPPED).
setIntermediateState(ContainerStatus.INITIALISING, false).
setEndState(ContainerStatus.READY).
setErrorState(ContainerStatus.INITIALISATION_FAILED).
addTransitionAction(action);
transitionBuilder.buildAndRegister();
}
public static boolean isKnownErrorState(ContainerStatus stat) {
return stat == ContainerStatus.INITIALISATION_FAILED;
}
public static boolean isSuccessfullEndState(ContainerStatus stat) {
return stat == ContainerStatus.READY;
}
}
/*
* Copyright (c) 2014-2015 University of Ulm
*
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership. Licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package de.uniulm.omi.cloudiator.lance.lca.containers.docker;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.uniulm.omi.cloudiator.lance.application.DeploymentContext;
import de.uniulm.omi.cloudiator.lance.application.component.DeployableComponent;
import de.uniulm.omi.cloudiator.lance.application.component.InPort;
import de.uniulm.omi.cloudiator.lance.container.spec.os.OperatingSystem;
import de.uniulm.omi.cloudiator.lance.container.standard.ContainerLogic;
import de.uniulm.omi.cloudiator.lance.lca.container.ContainerException;
import de.uniulm.omi.cloudiator.lance.lca.container.ComponentInstanceId;
import de.uniulm.omi.cloudiator.lance.lca.container.environment.BashExportBasedVisitor;
import de.uniulm.omi.cloudiator.lance.lca.container.port.DownstreamAddress;
import de.uniulm.omi.cloudiator.lance.lca.container.port.InportAccessor;
import de.uniulm.omi.cloudiator.lance.lca.container.port.NetworkHandler;
import de.uniulm.omi.cloudiator.lance.lca.container.port.PortDiff;
import de.uniulm.omi.cloudiator.lance.lca.container.port.PortRegistryTranslator;
import de.uniulm.omi.cloudiator.lance.lca.containers.docker.connector.DockerConnector;
import de.uniulm.omi.cloudiator.lance.lca.containers.docker.connector.DockerException;
import de.uniulm.omi.cloudiator.lance.lifecycle.HandlerType;
import de.uniulm.omi.cloudiator.lance.lifecycle.LifecycleActionInterceptor;
import de.uniulm.omi.cloudiator.lance.lifecycle.LifecycleHandlerType;
import de.uniulm.omi.cloudiator.lance.lifecycle.LifecycleStore;
import de.uniulm.omi.cloudiator.lance.lifecycle.detector.DetectorType;
public class DockerContainerLogic implements ContainerLogic, LifecycleActionInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger(DockerContainerManager.class);
private final ComponentInstanceId myId;