2 * ============LICENSE_START====================================
4 * =========================================================
5 * Copyright (C) 2019-2021 Nokia. All rights reserved.
6 * Copyright (C) 2023 AT&T Intellectual Property. All rights reserved.
7 * Copyright (C) 2023 Deutsche Telekom Intellectual Property. All rights reserved.
8 * =========================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================
23 package org.onap.dcae.common.publishing;
25 import org.onap.dcae.FileReader;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.testcontainers.containers.DockerComposeContainer;
29 import org.testcontainers.containers.wait.strategy.Wait;
33 import java.net.URISyntaxException;
36 final class DMaapContainer {
37 private static final String MR_COMPOSE_RESOURCE_NAME = "dmaap-msg-router/message-router-compose.yml";
38 private static final String DOCKER_COMPOSE_FILE_PATH = getDockerComposeFilePath(MR_COMPOSE_RESOURCE_NAME);
39 static final int KAFKA_SERVICE_EXPOSED_PORT = 9092;
40 static final String KAFKA_SERVICE_NAME = "kafka";
41 private static final Logger log = LoggerFactory.getLogger(DMaapContainer.class);
43 private DMaapContainer() {}
46 public static DockerComposeContainer createContainerInstance() {
48 URI dockercomposeuri = null;
50 dockercomposeuri = new URI(DOCKER_COMPOSE_FILE_PATH);
51 } catch (URISyntaxException e) {
52 log.error("Error while opening docker compose file.", e);
54 return new DockerComposeContainer(
55 new File(dockercomposeuri.getPath()))
56 .withExposedService(KAFKA_SERVICE_NAME, KAFKA_SERVICE_EXPOSED_PORT, Wait.forListeningPort())
57 .withLocalCompose(true);
62 private static String getDockerComposeFilePath(String resourceName) {
63 URL resource = DMaapContainer.class.getClassLoader()
64 .getResource(resourceName);
66 if (resource != null) return resource.getFile();
67 else throw new RuntimeException(String
68 .format("File %s does not exist", resourceName));