Search in sources :

Example 56 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8 by jboss-fuse.

the class AbstractManagedContainer method stop.

@Override
public final synchronized void stop() throws LifecycleException {
    assertNotDestroyed();
    try {
        if (state == State.STARTED) {
            doStop(configuration);
            state = State.STOPPED;
        }
    } catch (Exception ex) {
        throw new LifecycleException("Cannot stop container", ex);
    }
}
Also used : LifecycleException(io.fabric8.runtime.container.LifecycleException) LifecycleException(io.fabric8.runtime.container.LifecycleException) IOException(java.io.IOException)

Example 57 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8-maven-plugin by fabric8io.

the class DefaultControllerEnricherTest method enrichAndAssert.

protected void enrichAndAssert(int sizeOfObjects, int replicaCount) throws com.fasterxml.jackson.core.JsonProcessingException {
    // Setup a sample docker build configuration
    final BuildImageConfiguration buildConfig = new BuildImageConfiguration.Builder().ports(Arrays.asList("8080")).build();
    final TreeMap controllerConfig = new TreeMap();
    controllerConfig.put("replicaCount", String.valueOf(replicaCount));
    setupExpectations(buildConfig, controllerConfig);
    // Enrich
    DefaultControllerEnricher controllerEnricher = new DefaultControllerEnricher(context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    controllerEnricher.addMissingResources(builder);
    // Validate that the generated resource contains
    KubernetesList list = builder.build();
    assertEquals(sizeOfObjects, list.getItems().size());
    String json = KubernetesResourceUtil.toJson(list.getItems().get(0));
    assertThat(json, JsonPathMatchers.isJson());
    assertThat(json, JsonPathMatchers.hasJsonPath("$.spec.replicas", Matchers.equalTo(replicaCount)));
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) KubernetesList(io.fabric8.kubernetes.api.model.KubernetesList) TreeMap(java.util.TreeMap) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration)

Example 58 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8-maven-plugin by fabric8io.

the class PushMojo method customizeConfig.

/**
 * Customization hook called by the base plugin.
 *
 * @param configs configuration to customize
 * @return the configuration customized by our generators.
 */
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
    try {
        ProcessorConfig generatorConfig = ProfileUtil.blendProfileWithConfiguration(ProfileUtil.GENERATOR_CONFIG, profile, resourceDir, generator);
        GeneratorContext ctx = new GeneratorContext.Builder().config(generatorConfig).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:push").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(false).build();
        return GeneratorManager.generate(configs, ctx, true);
    } catch (Exception e) {
        throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
    }
}
Also used : GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 59 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8-maven-plugin by fabric8io.

the class ResourceMojo method generateResources.

private KubernetesList generateResources(List<ImageConfiguration> images) throws IOException, MojoExecutionException {
    // Manager for calling enrichers.
    openshiftDependencyResources = new OpenShiftDependencyResources(log);
    loadOpenShiftOverrideResources();
    EnricherContext.Builder ctxBuilder = new EnricherContext.Builder().project(project).session(session).goalFinder(goalFinder).config(extractEnricherConfig()).resources(resources).images(resolvedImages).log(log).useProjectClasspath(useProjectClasspath).openshiftDependencyResources(openshiftDependencyResources);
    if (resources != null) {
        ctxBuilder.namespace(resources.getNamespace());
    }
    EnricherManager enricherManager = new EnricherManager(resources, ctxBuilder.build());
    // Generate all resources from the main resource diretory, configuration and enrich them accordingly
    KubernetesListBuilder builder = generateAppResources(images, enricherManager);
    // Add resources found in subdirectories of resourceDir, with a certain profile
    // applied
    addProfiledResourcesFromSubirectories(builder, resourceDir, enricherManager);
    return builder.build();
}
Also used : EnricherContext(io.fabric8.maven.enricher.api.EnricherContext) EnricherManager(io.fabric8.maven.plugin.enricher.EnricherManager)

Example 60 with Configuration

use of io.fabric8.annotations.Configuration in project fabric8-maven-plugin by fabric8io.

the class BaseGenerator method addFrom.

/**
 * Add the base image either from configuration or from a given selector
 *
 * @param builder for the build image configuration to add the from to.
 */
protected void addFrom(BuildImageConfiguration.Builder builder) {
    String fromMode = getConfigWithSystemFallbackAndDefault(Config.fromMode, "fabric8.generator.fromMode", getFromModeDefault(context.getMode()));
    String from = getConfigWithSystemFallbackAndDefault(Config.from, "fabric8.generator.from", null);
    if ("docker".equalsIgnoreCase(fromMode)) {
        String fromImage = from;
        if (fromImage == null) {
            fromImage = fromSelector != null ? fromSelector.getFrom() : null;
        }
        builder.from(fromImage);
        log.info("Using Docker image %s as base / builder", fromImage);
    } else if ("istag".equalsIgnoreCase(fromMode)) {
        Map<String, String> fromExt = new HashMap<>();
        if (from != null) {
            ImageName iName = new ImageName(from);
            // user/project is considered to be the namespace
            String tag = iName.getTag();
            if (StringUtils.isBlank(tag)) {
                tag = "latest";
            }
            fromExt.put(OpenShiftBuildStrategy.SourceStrategy.name.key(), iName.getSimpleName() + ":" + tag);
            if (iName.getUser() != null) {
                fromExt.put(OpenShiftBuildStrategy.SourceStrategy.namespace.key(), iName.getUser());
            }
            fromExt.put(OpenShiftBuildStrategy.SourceStrategy.kind.key(), "ImageStreamTag");
        } else {
            fromExt = fromSelector != null ? fromSelector.getImageStreamTagFromExt() : null;
        }
        if (fromExt != null) {
            String namespace = fromExt.get(OpenShiftBuildStrategy.SourceStrategy.namespace.key());
            if (namespace != null) {
                log.info("Using ImageStreamTag '%s' from namespace '%s' as builder image", fromExt.get(OpenShiftBuildStrategy.SourceStrategy.name.key()), namespace);
            } else {
                log.info("Using ImageStreamTag '%s' as builder image", fromExt.get(OpenShiftBuildStrategy.SourceStrategy.name.key()));
            }
            builder.fromExt(fromExt);
        }
    } else {
        throw new IllegalArgumentException(String.format("Invalid 'fromMode' in generator configuration for '%s'", getName()));
    }
}
Also used : ImageName(io.fabric8.maven.docker.util.ImageName) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

IOException (java.io.IOException)29 HashMap (java.util.HashMap)23 File (java.io.File)22 Configuration (org.osgi.service.cm.Configuration)20 Map (java.util.Map)16 BootstrapConfiguration (io.fabric8.zookeeper.bootstrap.BootstrapConfiguration)15 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 Container (io.fabric8.api.Container)11 Profile (io.fabric8.api.Profile)11 RuntimeProperties (io.fabric8.api.RuntimeProperties)9 HashSet (java.util.HashSet)9 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)8 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)8 FabricException (io.fabric8.api.FabricException)7 FabricService (io.fabric8.api.FabricService)7 Properties (java.util.Properties)7 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)6 Util.readAsString (io.fabric8.arquillian.utils.Util.readAsString)5 URL (java.net.URL)5