Search in sources :

Example 16 with Result

use of io.fabric8.insight.metrics.model.Result in project carbon-apimgt by wso2.

the class KubernetesGatewayImpl method createServiceResource.

/**
 * Create a service in cms
 *
 * @param serviceTemplate Service template as a String
 * @param serviceName     Name of the service
 * @throws ContainerBasedGatewayException if failed to create a service
 */
private void createServiceResource(String serviceTemplate, String serviceName) throws ContainerBasedGatewayException {
    HasMetadata resource = getResourcesFromTemplate(serviceTemplate);
    try {
        if (resource instanceof Service) {
            // check whether there are existing service already
            if (client.services().inNamespace(namespace).withName(serviceName).get() == null) {
                log.debug("Deploying in CMS type: {} and the Service resource definition: {} ", cmsType, serviceTemplate);
                Service service = (Service) resource;
                Service result = client.services().inNamespace(namespace).create(service);
                log.info("Created Service : " + result.getMetadata().getName() + " in Namespace : " + result.getMetadata().getNamespace() + " in " + cmsType);
            } else {
                log.info("There exist a service with the same name in " + cmsType + ". Service name : " + serviceName);
            }
        } else {
            throw new ContainerBasedGatewayException("Loaded Resource is not a Service in " + cmsType + "! " + resource, ExceptionCodes.LOADED_RESOURCE_DEFINITION_IS_NOT_VALID);
        }
    } catch (KubernetesClientException e) {
        throw new ContainerBasedGatewayException("Error while creating container based gateway service in " + cmsType + "!", e, ExceptionCodes.DEDICATED_CONTAINER_GATEWAY_CREATION_FAILED);
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Service(io.fabric8.kubernetes.api.model.Service) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) KubernetesClientException(io.fabric8.kubernetes.client.KubernetesClientException)

Example 17 with Result

use of io.fabric8.insight.metrics.model.Result in project docker-maven-plugin by fabric8io.

the class QueryService method getLatestContainerForImage.

/**
 * Get the id of the latest container started for an image
 *
 * @param image for which its container are looked up
 * @return container or <code>null</code> if no container has been started for this image.
 * @throws DockerAccessException if the request fails
 */
public Container getLatestContainerForImage(String image) throws DockerAccessException {
    long newest = 0;
    Container result = null;
    for (Container container : getContainersForImage(image)) {
        long timestamp = container.getCreated();
        if (timestamp < newest) {
            continue;
        }
        newest = timestamp;
        result = container;
    }
    return result;
}
Also used : Container(io.fabric8.maven.docker.model.Container)

Example 18 with Result

use of io.fabric8.insight.metrics.model.Result in project docker-maven-plugin by fabric8io.

the class DockerAssemblyManagerTest method assemblyFiles.

@Test
public void assemblyFiles(@Injectable final MojoParameters mojoParams, @Injectable final MavenProject project, @Injectable final Assembly assembly) throws AssemblyFormattingException, ArchiveCreationException, InvalidAssemblerConfigurationException, MojoExecutionException, AssemblyReadException, IllegalAccessException {
    ReflectionUtils.setVariableValueInObject(assemblyManager, "trackArchiver", trackArchiver);
    new Expectations() {

        {
            mojoParams.getOutputDirectory();
            result = "target/";
            times = 3;
            mojoParams.getProject();
            project.getBasedir();
            result = ".";
            assemblyReader.readAssemblies((AssemblerConfigurationSource) any);
            result = Arrays.asList(assembly);
        }
    };
    BuildImageConfiguration buildConfig = createBuildConfig();
    assemblyManager.getAssemblyFiles("testImage", buildConfig, mojoParams, new AnsiLogger(new SystemStreamLog(), true, true));
}
Also used : Expectations(mockit.Expectations) SystemStreamLog(org.apache.maven.plugin.logging.SystemStreamLog) AnsiLogger(io.fabric8.maven.docker.util.AnsiLogger) BuildImageConfiguration(io.fabric8.maven.docker.config.BuildImageConfiguration) Test(org.junit.Test)

Example 19 with Result

use of io.fabric8.insight.metrics.model.Result in project docker-maven-plugin by fabric8io.

the class ConfigHelperTest method filter.

@Test
public void filter() throws Exception {
    List<ImageConfiguration> configs = Arrays.asList(new ImageConfiguration.Builder().name("test").build());
    CatchingLog logCatcher = new CatchingLog();
    List<ImageConfiguration> result = ConfigHelper.resolveImages(new AnsiLogger(logCatcher, true, true), configs, createResolver(), "bla", createCustomizer());
    assertEquals(0, result.size());
    assertTrue(resolverCalled);
    assertTrue(customizerCalled);
    assertTrue(logCatcher.getWarnMessage().contains("test"));
    assertTrue(logCatcher.getWarnMessage().contains("bla"));
}
Also used : AnsiLogger(io.fabric8.maven.docker.util.AnsiLogger) Test(org.junit.Test)

Example 20 with Result

use of io.fabric8.insight.metrics.model.Result in project docker-maven-plugin by fabric8io.

the class VolumeServiceTest method testCreateVolumeConfig.

@Test
public void testCreateVolumeConfig() throws Exception {
    final VolumeConfiguration config = new VolumeConfiguration.Builder().name("testVolume").driver("test").opts(withMap("opts")).labels(withMap("labels")).build();
    new Expectations() {

        {
            // Use a 'delegate' to verify the argument given directly. No need
            // for an 'intermediate' return method in the service just to check this.
            docker.createVolume(with(new Delegate<VolumeCreateConfig>() {

                void check(VolumeCreateConfig vcc) {
                    assertThat(vcc.getName(), is("testVolume"));
                    JSONObject vccJson = (JSONObject) JSONParser.parseJSON(vcc.toJson());
                    assertEquals(vccJson.get("Driver"), "test");
                }
            }));
            result = "testVolume";
        }
    };
    String volume = new VolumeService(docker).createVolume(config);
    assertEquals(volume, "testVolume");
}
Also used : Expectations(mockit.Expectations) VolumeCreateConfig(io.fabric8.maven.docker.access.VolumeCreateConfig) JSONObject(org.json.JSONObject) Delegate(mockit.Delegate) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)104 Expectations (mockit.Expectations)49 HashMap (java.util.HashMap)32 Map (java.util.Map)24 ArrayList (java.util.ArrayList)23 File (java.io.File)21 GitContext (io.fabric8.api.GitContext)20 IOException (java.io.IOException)20 Exchange (org.apache.camel.Exchange)20 Processor (org.apache.camel.Processor)20 DefaultPullPushPolicy (io.fabric8.git.internal.DefaultPullPushPolicy)18 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)17 Probe (io.fabric8.kubernetes.api.model.Probe)16 PatchResult (io.fabric8.patch.management.PatchResult)13 Properties (java.util.Properties)13 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)11 Patch (io.fabric8.patch.management.Patch)11 PatchException (io.fabric8.patch.management.PatchException)11 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)10 TreeMap (java.util.TreeMap)10