Search in sources :

Example 36 with Resource

use of io.fabric8.support.api.Resource in project fabric8 by jboss-fuse.

the class PatchApplyTest method deployment.

@Deployment
@StartLevelAware(autostart = true)
public static Archive<?> deployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "patch-apply-test.jar");
    archive.addPackage(CommandSupport.class.getPackage());
    archive.addPackage(IOHelpers.class.getPackage());
    archive.setManifest(new Asset() {

        @Override
        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleManifestVersion(2);
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleVersion("1.0.0");
            builder.addImportPackages(ServiceLocator.class, FabricService.class);
            builder.addImportPackages("io.fabric8.git");
            builder.addImportPackages(AbstractCommand.class, Action.class);
            builder.addImportPackage("org.apache.felix.service.command;status=provisional");
            builder.addImportPackages(ConfigurationAdmin.class, ServiceTracker.class, Logger.class);
            return builder.openStream();
        }
    });
    // add the original 'patchable' bundle version and the patch file to the test bundle as an extra resource
    archive.add(createPatchableBundle(ORIGINAL_VERSION), "/bundles", ZipExporter.class);
    archive.add(createPatchZip(), "/patches", ZipExporter.class);
    return archive;
}
Also used : Action(org.apache.felix.gogo.commands.Action) ServiceTracker(org.osgi.util.tracker.ServiceTracker) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AbstractCommand(org.apache.felix.gogo.commands.basic.AbstractCommand) Logger(org.slf4j.Logger) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) ServiceLocator(io.fabric8.api.gravia.ServiceLocator) FabricService(io.fabric8.api.FabricService) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) CommandSupport(io.fabric8.itests.support.CommandSupport) IOHelpers(io.fabric8.common.util.IOHelpers) StartLevelAware(org.jboss.arquillian.osgi.StartLevelAware) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 37 with Resource

use of io.fabric8.support.api.Resource in project halyard by spinnaker.

the class LocalDebianServiceProvider method getInstallCommand.

@Override
public String getInstallCommand(DeploymentDetails deploymentDetails, GenerateService.ResolvedConfiguration resolvedConfiguration, Map<String, String> installCommands) {
    Map<String, Object> bindings = new HashMap<>();
    List<SpinnakerService.Type> serviceTypes = new ArrayList<>(installCommands.keySet()).stream().map(SpinnakerService.Type::fromCanonicalName).collect(Collectors.toList());
    List<String> upstartNames = getLocalServices(serviceTypes).stream().filter(i -> resolvedConfiguration.getServiceSettings(i.getService()).getEnabled()).map(i -> ((LocalDebianService) i).getUpstartServiceName()).filter(Objects::nonNull).collect(Collectors.toList());
    List<String> systemdServiceConfigs = upstartNames.stream().map(n -> n + ".service").collect(Collectors.toList());
    List<String> serviceInstalls = serviceTypes.stream().map(t -> installCommands.get(t.getCanonicalName())).collect(Collectors.toList());
    TemplatedResource resource = new StringReplaceJarResource("/debian/init.sh");
    bindings.put("services", Strings.join(upstartNames, " "));
    bindings.put("systemd-service-configs", Strings.join(systemdServiceConfigs, " "));
    String upstartInit = resource.setBindings(bindings).toString();
    BillOfMaterials.ArtifactSources artifactSources = artifactService.getArtifactSources(deploymentDetails.getDeploymentName());
    resource = new StringReplaceJarResource("/debian/install.sh");
    bindings = new HashMap<>();
    bindings.put("prepare-environment", "true");
    bindings.put("install-redis", "true");
    bindings.put("debian-repository", artifactSourcesConfig.mergeWithBomSources(artifactSources).getDebianRepository());
    bindings.put("install-commands", String.join("\n", serviceInstalls));
    bindings.put("service-action", "restart");
    bindings.put("upstart-init", upstartInit);
    return resource.setBindings(bindings).toString();
}
Also used : DeploymentDetails(com.netflix.spinnaker.halyard.deploy.deployment.v1.DeploymentDetails) java.util(java.util) ArtifactSourcesConfig(com.netflix.spinnaker.halyard.config.config.v1.ArtifactSourcesConfig) Autowired(org.springframework.beans.factory.annotation.Autowired) ArtifactService(com.netflix.spinnaker.halyard.deploy.services.v1.ArtifactService) GenerateService(com.netflix.spinnaker.halyard.deploy.services.v1.GenerateService) SpinnakerRuntimeSettings(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.SpinnakerRuntimeSettings) Collectors(java.util.stream.Collectors) Component(org.springframework.stereotype.Component) LocalServiceProvider(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.local.LocalServiceProvider) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource) RemoteAction(com.netflix.spinnaker.halyard.core.RemoteAction) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) Strings(io.fabric8.utils.Strings) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) TemplatedResource(com.netflix.spinnaker.halyard.core.resource.v1.TemplatedResource) SpinnakerService(com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.SpinnakerService) BillOfMaterials(com.netflix.spinnaker.halyard.core.registry.v1.BillOfMaterials) StringReplaceJarResource(com.netflix.spinnaker.halyard.core.resource.v1.StringReplaceJarResource)

Example 38 with Resource

use of io.fabric8.support.api.Resource 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 39 with Resource

use of io.fabric8.support.api.Resource in project fabric8-maven-plugin by fabric8io.

the class ImageEnricher method mergeEnvVariables.

private void mergeEnvVariables(Container container) {
    List<EnvVar> env = container.getEnv();
    if (env == null) {
        env = new LinkedList<>();
        container.setEnv(env);
    }
    ResourceConfig resource = getContext().getResources();
    Map<String, String> userEnv = resource != null ? resource.getEnv() : null;
    if (userEnv != null) {
        for (Map.Entry<String, String> entry : userEnv.entrySet()) {
            EnvVar existingVariable = KubernetesResourceUtil.setEnvVarNoOverride(env, entry.getKey(), entry.getValue());
            if (existingVariable != null) {
                String actualValue = existingVariable.getValue();
                if (actualValue == null) {
                    actualValue = "retrieved using the downward API";
                }
                log.warn("Environment variable %s will not be overridden: trying to set the value %s, but its actual value will be %s", entry.getKey(), entry.getValue(), actualValue);
            }
        }
    }
}
Also used : EnvVar(io.fabric8.kubernetes.api.model.EnvVar) ResourceConfig(io.fabric8.maven.core.config.ResourceConfig) Map(java.util.Map)

Example 40 with Resource

use of io.fabric8.support.api.Resource in project fabric8-maven-plugin by fabric8io.

the class NameEnricher method getOrCreateMetadata.

private ObjectMeta getOrCreateMetadata(HasMetadata resource) {
    ObjectMeta metadata = resource.getMetadata();
    if (metadata == null) {
        metadata = new ObjectMeta();
        resource.setMetadata(metadata);
    }
    return metadata;
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta)

Aggregations

HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)25 Resource (io.fabric8.kubernetes.client.dsl.Resource)25 Map (java.util.Map)20 Test (org.junit.Test)20 IOException (java.io.IOException)19 HashMap (java.util.HashMap)16 Deployment (io.fabric8.kubernetes.api.model.extensions.Deployment)14 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)14 MixedOperation (io.fabric8.kubernetes.client.dsl.MixedOperation)14 Resource (org.osgi.resource.Resource)14 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)13 NonNamespaceOperation (io.fabric8.kubernetes.client.dsl.NonNamespaceOperation)13 ArrayList (java.util.ArrayList)13 Async (io.vertx.ext.unit.Async)12 File (java.io.File)10 ReplicationController (io.fabric8.kubernetes.api.model.ReplicationController)9 Service (io.fabric8.kubernetes.api.model.Service)9 KubernetesClientException (io.fabric8.kubernetes.client.KubernetesClientException)9 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)8 Bundle (org.osgi.framework.Bundle)7