aboutsummaryrefslogtreecommitdiffstats
path: root/ncomp-docker-adaptor/src/main/java/org/openecomp/ncomp/servers/docker/TestDockerRunLinks.java
blob: 0d92e908155e1adaeb9a77a0dc2881d2675e269d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*-
 * ============LICENSE_START==========================================
 * OPENECOMP - DCAE
 * ===================================================================
 * Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
 * ===================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END============================================
 */
	
package org.openecomp.ncomp.servers.docker;

import org.openecomp.ncomp.docker.ContainerOptions;
import org.openecomp.ncomp.docker.ContainerPortBindings;
import org.openecomp.ncomp.docker.ContainerRestartPolicy;
import org.openecomp.ncomp.docker.DockerFactory;
import org.openecomp.ncomp.sirius.manager.ISiriusServer;
import org.openecomp.ncomp.sirius.manager.ManagementServer;

public class TestDockerRunLinks implements ISiriusServer {
	
	private ManagementServer server;
	
	public static void main(String[] args) {
		
		TestDockerRunLinks t = new TestDockerRunLinks();
		
		String dockerRegistry = "cdf-2.novalocal:7113";
		String dockerImage = "dcae-mysql";
		String dockerImageTag = "5.7";
		String image = dockerRegistry + "/" + dockerImage + ":" + dockerImageTag;	
		
		ContainerOptions opts = DockerFactory.eINSTANCE.createContainerOptions();
		
		String containerName = dockerImage + "_kens_test";
		
		// container name
		opts.setName(containerName);
		
		// vm to container volume mapping
		opts.getVolumes().add("/var/log:/opt/app/logs");

		// publish exposed ports to an ephemeral vm port
		opts.setPublishAllPorts(true);
		
		// set restart policy 
		// if the docker engine is stopped and containers killed - this will 
		// instruct the docker engine to restart those containers when it 
		// is brought back up
		ContainerRestartPolicy restartPolicy = DockerFactory.eINSTANCE.createContainerRestartPolicy();
		restartPolicy.setNm("always");
		restartPolicy.setMaxRetryCnt(0);
		opts.setAutoRestart(restartPolicy);
		
		// mysql runtime arguments
		// not really necessary because we set these in the Dockerfile
		/*
		opts.getEnv().add("MYSQL_USER=nmsadm");
		opts.getEnv().add("MYSQL_PASSWORD=nmsadm");
		opts.getEnv().add("MYSQL_DATABASE=ucsnmp");
		opts.getEnv().add("MYSQL_ROOT_PASSWORD=dcae");
		*/

		System.err.println("Starting first container " + opts.getName() + " ...");
		t.dockerRun(image,opts);
		
		// create container to link to the previous one
		ContainerOptions linkOpts = DockerFactory.eINSTANCE.createContainerOptions();
		String linkedImage = dockerRegistry + "/" + "dcae-controller-snmptrap" + ":" + "5.7";
		linkOpts.getLinks().add(containerName + ":" + "mysql");
		linkOpts.setName("dcae-controller-snmptrap" + "_kens_test");
		linkOpts.setPublishAllPorts(true);
			
		System.err.println("Starting second container " + opts.getName() + " ...");
		t.dockerRun(linkedImage,linkOpts);
		
	}
	
	private void dockerRun(String image, ContainerOptions opts) {
		server = new ManagementServer();
		DockerDockerHost dockerd = new DockerDockerHost(this);
		
		dockerd.dockerRunWithOptions(image, opts);
	}
	
	@Override
	public ManagementServer getServer() {
		return server;
	}

}