Search in sources :

Example 1 with ServiceDescriptor

use of com.github.qzagarese.dockerunit.internal.ServiceDescriptor in project dockerunit by qzagarese.

the class DefaultServiceBuilder method executeOptionBuilders.

private CreateContainerCmd executeOptionBuilders(ServiceDescriptor descriptor, CreateContainerCmd cmd) {
    for (Annotation a : descriptor.getOptions()) {
        Class<? extends ExtensionInterpreter<?>> builderType = a.annotationType().getAnnotation(ExtensionMarker.class).value();
        ExtensionInterpreter<?> builder = null;
        Method buildMethod = null;
        try {
            builder = builderType.newInstance();
        } catch (Exception e) {
            throw new RuntimeException("Cannot instantiate " + ExtensionInterpreter.class.getSimpleName() + " of type " + builderType.getSimpleName() + " to handle annotation " + a.annotationType().getSimpleName() + " that has been detected on class " + descriptor.getInstance().getClass().getName(), e);
        }
        try {
            buildMethod = builderType.getDeclaredMethod("build", new Class<?>[] { ServiceDescriptor.class, CreateContainerCmd.class, a.annotationType() });
            cmd = (CreateContainerCmd) buildMethod.invoke(builder, descriptor, cmd, a);
        } catch (Exception e) {
            throw new RuntimeException("An error occurred while invoking the build method on builder class " + builderType.getName(), e);
        }
    }
    return cmd;
}
Also used : CreateContainerCmd(com.github.dockerjava.api.command.CreateContainerCmd) ServiceDescriptor(com.github.qzagarese.dockerunit.internal.ServiceDescriptor) Method(java.lang.reflect.Method) ExtensionInterpreter(com.github.qzagarese.dockerunit.annotation.ExtensionInterpreter) ExtensionMarker(com.github.qzagarese.dockerunit.annotation.ExtensionMarker) Annotation(java.lang.annotation.Annotation) NotFoundException(com.github.dockerjava.api.exception.NotFoundException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) ContainerException(com.github.qzagarese.dockerunit.exception.ContainerException)

Aggregations

CreateContainerCmd (com.github.dockerjava.api.command.CreateContainerCmd)1 NotFoundException (com.github.dockerjava.api.exception.NotFoundException)1 ExtensionInterpreter (com.github.qzagarese.dockerunit.annotation.ExtensionInterpreter)1 ExtensionMarker (com.github.qzagarese.dockerunit.annotation.ExtensionMarker)1 ContainerException (com.github.qzagarese.dockerunit.exception.ContainerException)1 ServiceDescriptor (com.github.qzagarese.dockerunit.internal.ServiceDescriptor)1 IOException (java.io.IOException)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 CompletionException (java.util.concurrent.CompletionException)1