Search in sources :

Example 26 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy in project fabric8 by jboss-fuse.

the class PatchServiceImplTest method testFailOnCorruptedZip.

@Test
public void testFailOnCorruptedZip() throws URISyntaxException, MalformedURLException {
    FabricService mockFabricService = Mockito.mock(FabricService.class);
    when(mockFabricService.getMavenRepoUploadURI()).thenReturn(new URI("http://dummy"));
    PatchServiceImpl patchService = new PatchServiceImpl(mockFabricService);
    Version version = Mockito.mock(Version.class);
    URL url = getClass().getClassLoader().getResource("corrupted_archive.zip");
    try {
        patchService.applyPatch(version, url, "not_relevant", "not_relevant");
        fail("Expected PatchException has not been triggered.");
    } catch (PatchException e) {
        assertNotNull(e);
        e.printStackTrace();
    } catch (Exception e) {
        fail("Note the expected exception: " + e);
        e.printStackTrace();
    }
}
Also used : Version(io.fabric8.api.Version) FabricService(io.fabric8.api.FabricService) PatchException(io.fabric8.api.PatchException) URI(java.net.URI) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) PatchException(io.fabric8.api.PatchException) Test(org.junit.Test)

Example 27 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy in project fabric8 by jboss-fuse.

the class KarafContainerRegistration method activateInternal.

private void activateInternal() {
    RuntimeProperties sysprops = runtimeProperties.get();
    runtimeIdentity = sysprops.getRuntimeIdentity();
    String version = sysprops.getProperty("fabric.version", ZkDefs.DEFAULT_VERSION);
    String profiles = sysprops.getProperty("fabric.profiles");
    try {
        if (profiles != null) {
            String versionNode = CONFIG_CONTAINER.getPath(runtimeIdentity);
            String profileNode = CONFIG_VERSIONS_CONTAINER.getPath(version, runtimeIdentity);
            createDefault(curator.get(), versionNode, version);
            createDefault(curator.get(), profileNode, profiles);
        }
        checkAlive();
        String domainsNode = CONTAINER_DOMAINS.getPath(runtimeIdentity);
        Stat stat = exists(curator.get(), domainsNode);
        if (stat != null) {
            deleteSafe(curator.get(), domainsNode);
        }
        boolean openshiftEnv = Strings.notEmpty(System.getenv("OPENSHIFT_FUSE_DIR"));
        ZooKeeperUtils.createDefault(curator.get(), CONTAINER_BINDADDRESS.getPath(runtimeIdentity), bootstrapConfiguration.get().getBindAddress());
        ZooKeeperUtils.createDefault(curator.get(), CONTAINER_RESOLVER.getPath(runtimeIdentity), getContainerResolutionPolicy(curator.get(), runtimeIdentity));
        setData(curator.get(), CONTAINER_LOCAL_HOSTNAME.getPath(runtimeIdentity), HostUtils.getLocalHostName());
        if (openshiftEnv) {
            setData(curator.get(), CONTAINER_LOCAL_IP.getPath(runtimeIdentity), System.getenv("OPENSHIFT_FUSE_IP"));
            setData(curator.get(), CONTAINER_PUBLIC_IP.getPath(runtimeIdentity), HostUtils.getLocalIp());
        } else {
            setData(curator.get(), CONTAINER_LOCAL_IP.getPath(runtimeIdentity), HostUtils.getLocalIp());
        }
        // Mostly usable for adding values when creating containers without an existing ensemble.
        for (String resolver : ZkDefs.VALID_RESOLVERS) {
            String address = (String) bootstrapConfiguration.get().getConfiguration().get(resolver);
            if (address != null && !address.isEmpty() && exists(curator.get(), CONTAINER_ADDRESS.getPath(runtimeIdentity, resolver)) == null) {
                setData(curator.get(), CONTAINER_ADDRESS.getPath(runtimeIdentity, resolver), address);
            }
        }
        ip = getSubstitutedData(curator.get(), getContainerPointer(curator.get(), runtimeIdentity));
        setData(curator.get(), CONTAINER_IP.getPath(runtimeIdentity), ip);
        if (Boolean.parseBoolean(runtimeProperties.get().getProperty("service.geoip.enabled", "false"))) {
            createDefault(curator.get(), CONTAINER_GEOLOCATION.getPath(runtimeIdentity), geoLocationService.get().getGeoLocation());
        }
        // We are creating a dummy container object, since this might be called before the actual container is ready.
        Container current = new ImmutableContainerBuilder().id(runtimeIdentity).ip(ip).build();
        if (System.getProperty(SystemProperties.JAVA_RMI_SERVER_HOSTNAME) == null) {
            System.setProperty(SystemProperties.JAVA_RMI_SERVER_HOSTNAME, current.getIp());
        }
        registerJmx(current);
        registerSsh(current);
        registerHttp(current);
        // Set the port range values
        String minimumPort = sysprops.getProperty(ZkDefs.MINIMUM_PORT);
        if (minimumPort == null) {
            String minPort = (String) bootstrapConfiguration.get().getConfiguration().get("minimum.port");
            minimumPort = minPort;
        }
        String maximumPort = sysprops.getProperty(ZkDefs.MAXIMUM_PORT);
        if (maximumPort == null) {
            String maxPort = (String) bootstrapConfiguration.get().getConfiguration().get("maximum.port");
            maximumPort = maxPort;
        }
        createDefault(curator.get(), CONTAINER_PORT_MIN.getPath(runtimeIdentity), minimumPort);
        createDefault(curator.get(), CONTAINER_PORT_MAX.getPath(runtimeIdentity), maximumPort);
    } catch (Exception e) {
        LOGGER.warn("Error updating Fabric Container information. This exception will be ignored.", e);
    }
}
Also used : Container(io.fabric8.api.Container) Stat(org.apache.zookeeper.data.Stat) ImmutableContainerBuilder(io.fabric8.internal.ImmutableContainerBuilder) RuntimeProperties(io.fabric8.api.RuntimeProperties) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Example 28 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy in project fabric8 by jboss-fuse.

the class OpenShiftPipelineTest method testPipelinesFromConfigMap.

@Test
public void testPipelinesFromConfigMap() throws Exception {
    String namespace = "myproject";
    final ConfigMap configMap = loadTestConfigMap();
    server.expect().withPath("/api/v1/namespaces/" + namespace + "/configmaps/" + FABRIC8_PIPELINES).andReturn(200, configMap).once();
    PipelineConfiguration configuration = PipelineConfiguration.loadPipelineConfiguration(getKubernetesClient(), namespace);
    assertJobName(configuration, "foo", "dummy", PipelineKind.CD);
    assertJobName(configuration, "bar", "dummy", PipelineKind.CI);
    assertJobName(configuration, "whatnot", "dummy", PipelineKind.Developer);
    assertJobName(configuration, "random", "master", "git@github.com:fabric8io/random.git", PipelineKind.CD);
    assertJobName(configuration, "random", "master", "https://github.com/fabric8io/random.git", PipelineKind.CD);
    assertJobName(configuration, "random", "not-master", "https://github.com/fabric8io/random.git", PipelineKind.Developer);
    assertJobName(configuration, "random", "master", "https://github.com/bar/foo.git", PipelineKind.Developer);
    assertJobName(configuration, "random", "master", "git@github.com:bar/foo.git", PipelineKind.Developer);
    // lets show we can opt out of CD pipelines for specific builds in an organisation if required
    assertJobName(configuration, "random", "master", "https://github.com/random/whatnot.git", PipelineKind.Developer);
    assertJobName(configuration, "random", "release", "https://github.com/random/whatnot.git", PipelineKind.CD);
    assertJobName(configuration, "random", "whatever", "https://github.com/random/whatnot.git", PipelineKind.CI);
}
Also used : PipelineConfigurationParseTest.loadTestConfigMap(io.fabric8.kubernetes.api.pipelines.PipelineConfigurationParseTest.loadTestConfigMap) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Test(org.junit.Test)

Example 29 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy in project fabric8-maven-plugin by fabric8io.

the class TriggersAnnotationEnricherTest method testNoEnrichment.

@Test
public void testNoEnrichment() {
    KubernetesListBuilder builder = new KubernetesListBuilder().addToItems(new JobBuilder().withNewMetadata().addToAnnotations("dummy", "annotation").endMetadata().withNewSpec().withNewTemplate().withNewSpec().withContainers(createContainers("c1", "is1:latest", "c2", "is2:latest")).endSpec().endTemplate().endSpec().build());
    TriggersAnnotationEnricher enricher = new TriggersAnnotationEnricher(context);
    enricher.enrich(PlatformMode.kubernetes, builder);
    Job res = (Job) builder.build().getItems().get(0);
    String triggers = res.getMetadata().getAnnotations().get("image.openshift.io/triggers");
    assertNull(triggers);
}
Also used : KubernetesListBuilder(io.fabric8.kubernetes.api.model.KubernetesListBuilder) JobBuilder(io.fabric8.kubernetes.api.model.batch.JobBuilder) Job(io.fabric8.kubernetes.api.model.batch.Job) Test(org.junit.Test)

Example 30 with Dummy

use of io.fabric8.kubernetes.examples.crds.Dummy in project strimzi by strimzi.

the class TopicSerializationTest method testTopicCommandSerde.

@Test
public void testTopicCommandSerde() {
    TopicCommandSerde serde = new TopicCommandSerde();
    Topic.Builder builder = new Topic.Builder();
    builder.withTopicName("foobar");
    builder.withNumReplicas((short) 1);
    builder.withNumPartitions(2);
    builder.withConfigEntry("cleanup.policy", "bar");
    ObjectMeta metadata = new ObjectMeta();
    builder.withMetadata(metadata);
    Topic topic = builder.build();
    TopicCommand data = TopicCommand.create(topic);
    byte[] bytes = serde.serialize("dummy", data);
    data = serde.deserialize("dummy", bytes);
    Assertions.assertEquals(TopicCommand.Type.CREATE, data.getType());
    Assertions.assertEquals(topic, data.getTopic());
    Assertions.assertEquals(TopicCommand.CURRENT_VERSION, data.getVersion());
    TopicName tn = new TopicName("deleteme");
    data = TopicCommand.delete(tn);
    bytes = serde.serialize("dummy", data);
    data = serde.deserialize("dummy", bytes);
    Assertions.assertEquals(TopicCommand.Type.DELETE, data.getType());
    Assertions.assertEquals(tn, data.getName());
    Assertions.assertEquals(TopicCommand.CURRENT_VERSION, data.getVersion());
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) NewTopic(org.apache.kafka.clients.admin.NewTopic) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)16 Test (org.junit.Test)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)8 Pod (io.fabric8.kubernetes.api.model.Pod)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Secret (io.fabric8.kubernetes.api.model.Secret)6 List (java.util.List)6 GenericKubernetesResource (io.fabric8.kubernetes.api.model.GenericKubernetesResource)5 KubernetesClientBuilder (io.fabric8.kubernetes.client.KubernetesClientBuilder)5 Resource (io.fabric8.kubernetes.client.dsl.Resource)5 Date (java.util.Date)5 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)4 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)4 KubernetesVersion (io.strimzi.operator.KubernetesVersion)4 PlatformFeaturesAvailability (io.strimzi.operator.PlatformFeaturesAvailability)4 ClusterOperatorConfig (io.strimzi.operator.cluster.ClusterOperatorConfig)4 KafkaVersionTestUtils (io.strimzi.operator.cluster.KafkaVersionTestUtils)4 ResourceUtils (io.strimzi.operator.cluster.ResourceUtils)4 ResourceOperatorSupplier (io.strimzi.operator.cluster.operator.resource.ResourceOperatorSupplier)4