Commit 3803c134 authored by Joerg Domaschka's avatar Joerg Domaschka Committed by GitHub

Merge pull request #19 from cloudiator/v0.3

V0.3-rc1
parents a060f05f 4fdb0d65
......@@ -5,3 +5,4 @@ target/
.project
.settings
/bin/
/classes/
package de.uniulm.omi.cloudiator.lance.lca.container;
public class ContainerConfigurationException extends ContainerException {
private static final long serialVersionUID = 1L;
public ContainerConfigurationException() {
super();
}
public ContainerConfigurationException(String message, Throwable cause) {
super(message, cause);
}
public ContainerConfigurationException(String message) {
super(message);
}
public ContainerConfigurationException(Throwable cause) {
super(cause);
}
}
......@@ -18,7 +18,7 @@
package de.uniulm.omi.cloudiator.lance.lca.container;
public final class ContainerException extends Exception {
public class ContainerException extends Exception {
private static final long serialVersionUID = 3097082722316018152L;
......
package de.uniulm.omi.cloudiator.lance.lca.container;
public class ContainerOperationException extends ContainerException {
public ContainerOperationException() {
super();
}
public ContainerOperationException(String message, Throwable cause) {
super(message, cause);
}
public ContainerOperationException(String message) {
super(message);
}
public ContainerOperationException(Throwable cause) {
super(cause);
}
}
......@@ -57,6 +57,11 @@ public enum ContainerStatus implements State {
READY,
SHUTTING_DOWN,
DESTROYED,
ERROR,
CREATION_FAILED,
BOOTSTRAPPING_FAILED,
INITIALISATION_FAILED,
UNKNOWN,
;
}
package de.uniulm.omi.cloudiator.lance.lca.container;
public class UnexpectedContainerStateException extends ContainerException {
public UnexpectedContainerStateException() {
super();
}
public UnexpectedContainerStateException(String message, Throwable cause) {
super(message, cause);
}
public UnexpectedContainerStateException(String message) {
super(message);
}
public UnexpectedContainerStateException(Throwable cause) {
super(cause);
}
}
......@@ -57,7 +57,7 @@ final class AppInstanceContainer {
void addComponentProperty(ComponentId cid, ComponentInstanceId cinstId, String property, Object value) {
ComponentInstanceContainer c = comps.get(cid);
if(c == null)
throw new IllegalArgumentException("not known: " + cid);
throw new IllegalArgumentException("component not known: " + cid);
c.addComponentProperty(cinstId, property, value);
}
......
......@@ -73,13 +73,14 @@ final class ComponentInstanceContainer {
if(props == null)
throw new IllegalArgumentException("not known: " + cinstId);
Object old = props.put(property, value);
String add = "";
if(old != null) {
LOGGER.warn("warning: overriding value!");
add = " (old value was " + old + ")";
}
//FIXME: wake up listeners (?)
LOGGER.error("TODO: wake up listeners");
LOGGER.info("LcaRegistry: added property: " + this + "/" + cinstId + "." + property + "=" + value);
LOGGER.info("LcaRegistry: added property: " + this + "/" + cinstId + "." + property + "=" + value + old);
}
public void addComponentInstance(ComponentInstanceId cinstId) {
......
......@@ -87,7 +87,7 @@ public final class RemoteRegistryImpl implements RmiLcaRegistry {
@Override
public String getComponentProperty(ApplicationInstanceId appInstId,
ComponentId compId, ComponentInstanceId myId, String name) {
ComponentId compId, ComponentInstanceId myId, String name) throws RemoteException {
AppInstanceContainer c = apps.get(appInstId);
if(c == null)
......
......@@ -22,5 +22,5 @@ import java.io.Serializable;
public interface LifecycleHandler extends Serializable {
void execute(ExecutionContext ec);
void execute(ExecutionContext ec) throws LifecycleException;
}
......@@ -69,8 +69,7 @@ public enum LifecycleHandlerType implements State, HandlerType {
*/
PRE_START(PreStartHandler.class, DefaultFactories.PRE_START_FACTORY),
/**
* may be used for checking that required operating system
* files are available, like files, disk space, and port
* starts the component instance
*/
START(StartHandler.class, DefaultFactories.START_FACTORY),
/**
......@@ -90,6 +89,13 @@ public enum LifecycleHandlerType implements State, HandlerType {
* may be used to release external resources
*/
POST_STOP(PostStopHandler.class, DefaultFactories.POST_STOP_FACTORY),
INIT_FAILED(VoidHandler.class, DefaultFactories.VOID_FACTORY),
INSTALL_FAILED(VoidHandler.class, DefaultFactories.VOID_FACTORY),
STARTUP_FAILED(VoidHandler.class, DefaultFactories.VOID_FACTORY),
TERMINATION_FAILED(VoidHandler.class, DefaultFactories.VOID_FACTORY),
UNEXPECTED_EXECUTION_STOP(VoidHandler.class, DefaultFactories.VOID_FACTORY),
UNKNOWN(VoidHandler.class, DefaultFactories.VOID_FACTORY),
;
private final Class<? extends LifecycleHandler> handlerType;
......
......@@ -24,6 +24,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.uniulm.omi.cloudiator.lance.lifecycle.detector.StartDetector;
import de.uniulm.omi.cloudiator.lance.lifecycle.detector.StopDetector;
public class LifecycleStore implements Serializable {
......@@ -32,8 +33,9 @@ public class LifecycleStore implements Serializable {
private static final long serialVersionUID = 1L;
private final LifecycleHandler[] handlers;
private final StartDetector startDetector;
private final StopDetector stopDetector;
LifecycleStore(LifecycleHandler[] handlersParam, StartDetector startDetectorParam) {
LifecycleStore(LifecycleHandler[] handlersParam, StartDetector startDetectorParam, StopDetector stopDetectorParam) {
handlers = handlersParam;
assert handlers.length == LifecycleHandlerType.values().length : "array too small";
for(LifecycleHandlerType t : LifecycleHandlerType.values()) {
......@@ -42,6 +44,7 @@ public class LifecycleStore implements Serializable {
throw new IllegalStateException("not the correct lifecycle handler");
}
startDetector = startDetectorParam;
stopDetector = stopDetectorParam;
}
public <T extends LifecycleHandler> T getHandler(LifecycleHandlerType t, Class<T> type) {
......@@ -69,4 +72,8 @@ public class LifecycleStore implements Serializable {
public StartDetector getStartDetector() {
return startDetector;
}
public StopDetector getStopDetector() {
return stopDetector;
}
}
/*
* 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.lifecycle;
import de.uniulm.omi.cloudiator.lance.lifecycle.detector.StartDetector;
public final class LifecycleStoreBuilder {
private final LifecycleHandler[] handlers = new LifecycleHandler[LifecycleHandlerType.values().length];
private volatile StartDetector startDetector;
public LifecycleStoreBuilder() {
// empty!
}
public synchronized LifecycleStoreBuilder setStartDetector(StartDetector start) {
if(startDetector == null || startDetector == start) {
startDetector = start;
} else {
throw new IllegalStateException("start detector has already been set.");
}
return this;
}
public LifecycleStoreBuilder setHandler(LifecycleHandler h, LifecycleHandlerType t) {
if(h == null)
throw new NullPointerException();
Class<?> superClass = t.getTypeClass();
Class<?> inheritCla = h.getClass();
if(! superClass.isAssignableFrom(inheritCla)) {
throw new IllegalArgumentException("handler types do not match: " + h.getClass() + " vs. " + t.getTypeClass());
}
if(t == LifecycleHandlerType.NEW) {
throw new IllegalArgumentException("cannot set a handler for 'NEW'. " + "This event is a system event");
}
handlers[t.ordinal()] = h;
return this;
}
public LifecycleStore build() {
for(LifecycleHandlerType t : LifecycleHandlerType.values()) {
if(handlers[t.ordinal()] == null) {
handlers[t.ordinal()] = t.getDefaultImplementation();
}
}
if(startDetector == null) {
throw new NullPointerException("start detector cannot be null");
}
return new LifecycleStore(handlers, startDetector);
}
}
/*
* 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.lifecycle;
import de.uniulm.omi.cloudiator.lance.lifecycle.detector.StartDetector;
import de.uniulm.omi.cloudiator.lance.lifecycle.detector.StopDetector;
public final class LifecycleStoreBuilder {
private final LifecycleHandler[] handlers = new LifecycleHandler[LifecycleHandlerType.values().length];
private volatile StartDetector startDetector;
private volatile StopDetector stopDetector;
public LifecycleStoreBuilder() {
// empty!
}
public synchronized LifecycleStoreBuilder setStartDetector(StartDetector start) {
if(startDetector == null || startDetector == start) {
startDetector = start;
} else {
throw new IllegalStateException("start detector has already been set.");
}
return this;
}
public LifecycleStoreBuilder setHandler(LifecycleHandler h, LifecycleHandlerType t) {
if(h == null)
throw new NullPointerException();
Class<?> superClass = t.getTypeClass();
Class<?> inheritCla = h.getClass();
if(! superClass.isAssignableFrom(inheritCla)) {
throw new IllegalArgumentException("handler types do not match: " + h.getClass() + " vs. " + t.getTypeClass());
}
if(t == LifecycleHandlerType.NEW) {
throw new IllegalArgumentException("cannot set a handler for 'NEW'. " + "This event is a system event");
}
handlers[t.ordinal()] = h;
return this;
}
public LifecycleStore build() {
for(LifecycleHandlerType t : LifecycleHandlerType.values()) {
if(handlers[t.ordinal()] == null) {
handlers[t.ordinal()] = t.getDefaultImplementation();
}
}
if(startDetector == null) {
throw new NullPointerException("start detector cannot be null");
}
return new LifecycleStore(handlers, startDetector, stopDetector);
}
}
......@@ -223,8 +223,6 @@ final class BashStartDetectorHandler implements StartDetector {
BashExecutionHelper.executeCommands(os, ec, commands);
ExecutionResult result = BashExecutionHelper.doExecuteCommand(false, "echo -n \"$STARTED\"", ec.getShell());
if(result.isSuccess()) {
// return values for docker is:
// \nfalse\n0\n
if("true".equals(result.getOutput().trim())) {
return DetectorState.DETECTED;
}
......
......@@ -44,7 +44,6 @@ final class BashExecutionHelper {
}
static ExecutionResult doExecuteCommand(boolean blocking, String command, Shell shell) {
// TODO: evaluate return values of commands and throw exceptions //
if(blocking) {
return shell.executeBlockingCommand(command);
}
......
......@@ -30,7 +30,6 @@ import de.uniulm.omi.cloudiator.lance.lifecycle.LifecycleHandlerType;
public interface StartDetector extends Detector {
DetectorState execute(ExecutionContext ec);
// empty interface; methods not yet fixed //
}
......
......@@ -18,6 +18,8 @@
package de.uniulm.omi.cloudiator.lance.lifecycle.detector;
import de.uniulm.omi.cloudiator.lance.lifecycle.ExecutionContext;
/**
* may be used to notify USM that the service instance has stopped,
* be it intended or unintended
......@@ -25,5 +27,6 @@ package de.uniulm.omi.cloudiator.lance.lifecycle.detector;
* @author Joerg Domaschka
*/
public interface StopDetector extends Detector {
// empty interface; methods not yet fixed //
DetectorState execute(ExecutionContext ec);
}
......@@ -20,4 +20,5 @@ package de.uniulm.omi.cloudiator.lance.util.state;
public interface State {
// a simple marker interface //
// boolean isErrorState();
}
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 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 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;