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 * =========================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=====================================
22 package org.onap.dcae.common.publishing;
24 import org.onap.dcae.FileReader;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.testcontainers.containers.DockerComposeContainer;
31 import java.net.URISyntaxException;
34 final class DMaapContainer {
35 private static final String MR_COMPOSE_RESOURCE_NAME = "dmaap-msg-router/message-router-compose.yml";
36 private static final String DOCKER_COMPOSE_FILE_PATH = getDockerComposeFilePath(MR_COMPOSE_RESOURCE_NAME);
37 static final int DMAAP_SERVICE_EXPOSED_PORT = 3904;
38 static final String DMAAP_SERVICE_NAME = "onap-dmaap";
39 private static final Logger log = LoggerFactory.getLogger(DMaapContainer.class);
41 private DMaapContainer() {}
44 public static DockerComposeContainer createContainerInstance() {
46 URI dockercomposeuri = null;
48 dockercomposeuri = new URI(DOCKER_COMPOSE_FILE_PATH);
49 } catch (URISyntaxException e) {
50 log.error("Error while opening docker compose file.", e);
52 return new DockerComposeContainer(
53 new File(dockercomposeuri.getPath()))
54 .withExposedService(DMAAP_SERVICE_NAME, DMAAP_SERVICE_EXPOSED_PORT)
55 .withLocalCompose(true);
60 private static String getDockerComposeFilePath(String resourceName) {
61 URL resource = DMaapContainer.class.getClassLoader()
62 .getResource(resourceName);
64 if (resource != null) return resource.getFile();
65 else throw new RuntimeException(String
66 .format("File %s does not exist", resourceName));