Commit 7b2cd0b8 authored by Joerg Domaschka's avatar Joerg Domaschka Committed by GitHub

Merge pull request #20 from cloudiator/v0.3

V0.3
parents 3803c134 6e809dd2
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;
}
}
......@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
import de.uniulm.omi.cloudiator.lance.LcaConstants;
import de.uniulm.omi.cloudiator.lance.lca.LifecycleAgent;
import de.uniulm.omi.cloudiator.lance.util.Registrator;
import de.uniulm.omi.cloudiator.lance.util.Version;
public final class LifecycleAgentBooter {
......@@ -32,7 +33,7 @@ public final class LifecycleAgentBooter {
private static volatile LifecycleAgentImpl lca;
public static void main(String[] args) {
LOGGER.info("LifecycleAgentBooter: starting.");
LOGGER.info("LifecycleAgentBooter: starting. running version: " + Version.getVersionString());
lca = createAgentImplementation();
LifecycleAgent stub = reg.export(lca, LcaConstants.AGENT_RMI_PORT);
......
/*
* 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;