diff options
Diffstat (limited to 'dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae')
5 files changed, 774 insertions, 0 deletions
diff --git a/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/docker/manager/tools/Generator.java b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/docker/manager/tools/Generator.java new file mode 100644 index 0000000..49ba09f --- /dev/null +++ b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/docker/manager/tools/Generator.java @@ -0,0 +1,96 @@ + +/*- + * ============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.dcae.controller.service.docker.manager.tools;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.EPackage;
+
+import org.openecomp.ncomp.sirius.manager.controllermodel.ControllerModel;
+import org.openecomp.ncomp.sirius.manager.controllermodel.ControllermodelFactory;
+import org.openecomp.ncomp.sirius.manager.generator.ControllerGenerator;
+import org.openecomp.ncomp.gwt.siriusportal.model.*;
+import org.openecomp.ncomp.sirius.manager.server.ServerPackage;
+import org.openecomp.dcae.controller.service.docker.DockerFactory;
+import org.openecomp.dcae.controller.service.dockermanager.DockermanagerFactory;
+import org.openecomp.utils.YamlToJava;
+
+public class Generator {
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ @SuppressWarnings("unused")
+ ServerPackage f = ServerPackage.eINSTANCE;
+ genManager();
+ genService();
+ }
+
+ public static void genManager() {
+ EObject o = DockermanagerFactory.eINSTANCE.createDockerManager();
+ EPackage p = o.eClass().getEPackage();
+ String dir = p.getNsURI().replaceAll(p.getNsPrefix()+'$',"") + "servers." + p.getNsPrefix();
+ dir = "src/main/sirius-gen/" + dir.replace('.', '/');
+ ControllerModel m = ControllermodelFactory.eINSTANCE.createControllerModel();
+ m.setTemplateDirectory("../../dcae-org.openecomp.ncomp.sirius.manager/ncomp-sirius-manager-generator/src/main/templates");
+ m.setPrefix("Dcae");
+ m.setPluginName(p.getNsURI());
+ m.setName("ControllerServiceDockerManager");
+ m.setTitle("ControllerServiceDockerManager");
+ ControllerGenerator g = new ControllerGenerator(o, m);
+ g.setEnableIRequestHandler(false);
+ g.setEnableISiriusPlugin(false);
+ g.addFactory("org.openecomp.ncomp.servers.docker.DockerDockerFactory");
+ g.addFactory(DockerFactory.eINSTANCE);
+ EObject gui = ModelFactory.eINSTANCE.createGuiClientApi();
+ g.addObject("gui", gui, m);
+ g.generate(dir);
+ g.generateScripts("src/main/server-gen/bin", "controller-service-docker-manager");
+ String pName = p.getNsURI().replaceAll(p.getNsPrefix()+'$',"") + "servers." + p.getNsPrefix() +".logging";
+// YamlToJava.convert("src/main/resources/DockerAdaptor.yaml", dir + "/logging", pName);
+ YamlToJava.convert("src/main/sirius-gen/DockerManager.yaml", dir + "/logging", pName);
+ String pName1 = p.getNsURI().replaceAll(p.getNsPrefix()+'$',"") + "servers." + p.getNsPrefix() +".gui.logging";
+ YamlToJava.convert("src/main/sirius-gen/GuiClientApi.yaml", dir + "/gui/logging", pName1);
+ }
+
+ public static void genService() {
+ EObject o = DockerFactory.eINSTANCE.createDockerService();
+ EPackage p = o.eClass().getEPackage();
+ String dir = p.getNsURI().replaceAll(p.getNsPrefix()+"$", "") + "servers." + p.getNsPrefix();
+ dir = "src/main/sirius-gen/" + dir.replace('.', '/');
+ ControllerModel m = ControllermodelFactory.eINSTANCE.createControllerModel();
+ m.setTemplateDirectory("../../dcae-org.openecomp.ncomp.sirius.manager/ncomp-sirius-manager-generator/src/main/templates");
+ m.setPrefix("Dcae");
+ m.setPluginName(p.getNsURI());
+ m.setName("ControllerServiceDockerService");
+ m.setTitle("ControllerServiceDockerService");
+ ControllerGenerator g = new ControllerGenerator(o, m);
+ g.setEnableIRequestHandler(false);
+ g.setEnableISiriusPlugin(true);
+ g.generate(dir);
+ String pName = p.getNsURI().replaceAll(p.getNsPrefix()+'$',"") + "servers." + p.getNsPrefix() +".logging";
+// YamlToJava.convert("src/main/resources/DcaeServiceDockerHost.yaml", dir + "/logging", pName);
+ YamlToJava.convert("src/main/sirius-gen/DockerService.yaml", dir + "/logging", pName);
+
+ }
+
+}
diff --git a/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/docker/manager/tools/TestServiceToManager.java b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/docker/manager/tools/TestServiceToManager.java new file mode 100644 index 0000000..7623fa8 --- /dev/null +++ b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/docker/manager/tools/TestServiceToManager.java @@ -0,0 +1,86 @@ + +/*- + * ============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.dcae.controller.service.docker.manager.tools; + +import org.openecomp.dcae.controller.core.server.ServerFactory; +import org.openecomp.dcae.controller.service.docker.DockerFactory; +import org.openecomp.dcae.controller.service.docker.DockerService; +import org.openecomp.dcae.controller.service.docker.DockerServiceInstance; +import org.openecomp.dcae.controller.service.docker.host.servers.manager.DcaeManagerFactory; +import org.openecomp.dcae.controller.service.docker.host.servers.service.DcaeServiceFactory; +import org.openecomp.dcae.controller.service.docker.host.service.DockerHostService; +import org.openecomp.dcae.controller.service.docker.host.service.DockerHostServiceInstance; +import org.openecomp.dcae.controller.service.docker.host.service.ServiceFactory; +import org.openecomp.dcae.controller.service.servers.docker.DcaeDockerFactory; +import org.openecomp.dcae.controller.service.vm.PhysicalMachine; +import org.openecomp.dcae.controller.service.vm.VmFactory; +import org.openecomp.ncomp.sirius.manager.ISiriusServer; +import org.openecomp.ncomp.sirius.manager.ManagementServer; + +// Testing service from inside standard Java Process +// This connects to a manager server +public class TestServiceToManager implements ISiriusServer { + + public static void main(String[] args) { + TestServiceToManager t = new TestServiceToManager(); + t.test(); + } + private ManagementServer server; + public void test() { + // setup docker host + server = new ManagementServer(); + + DcaeServiceFactory f1 = new DcaeServiceFactory(this); + DockerHostService s1 = f1.createDockerHostService(); + DockerHostServiceInstance i1 = f1.createDockerHostServiceInstance(); + PhysicalMachine p = VmFactory.eINSTANCE.createPhysicalMachine(); + i1.getServers().add(p); + s1.getInstances().add(i1); + i1.setName("dh-i1"); + s1.setName("dh-s1"); + // Setup connection parameters. + p.setPublicIp("localhost"); + p.setManagerPortNumber(9911); + // setup docker service instance + DockerFactory f = new DcaeDockerFactory(this); + DockerService s = f.createDockerService(); + DockerServiceInstance i = f.createDockerServiceInstance(); + s.getInstances().add(i); + i.setName("d-i"); + s.setName("d-s"); + String dockerRegistry = "cdf-2.novalocal:8453"; + String dockerImage = "dockerdemo_test5"; + String dockerImageTag = "1.0.2"; + String image = dockerRegistry + "/" + dockerImage + ":" + dockerImageTag; + i.setImage(image); +// s.pollManagerConfiguration("docker"); + server.setObject(s1); + s.deploy(i.getName(), "/instances/" + i1.getName()); + // TODO more examples + } + @Override + public ManagementServer getServer() { + // TODO Auto-generated method stub + return server; + } + +} diff --git a/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/servers/docker/DcaeDockerServiceProvider.java b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/servers/docker/DcaeDockerServiceProvider.java new file mode 100644 index 0000000..e653107 --- /dev/null +++ b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/servers/docker/DcaeDockerServiceProvider.java @@ -0,0 +1,342 @@ + +/*- + * ============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.dcae.controller.service.servers.docker; + +import java.util.Date; + +import org.apache.log4j.Logger; +import org.eclipse.emf.common.util.BasicEList; +import org.eclipse.emf.common.util.EList; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.json.JSONObject; + +import org.openecomp.dcae.controller.core.service.DcaeServiceContainer; +import org.openecomp.dcae.controller.core.service.HealthTestResponse; +import org.openecomp.dcae.controller.core.service.HealthTestStatus; +import org.openecomp.dcae.controller.core.service.ServiceFactory; +import org.openecomp.dcae.controller.core.stream.DcaeStream; +import org.openecomp.dcae.controller.core.stream.DmaapStream; +import org.openecomp.dcae.controller.service.docker.DockerService; +import org.openecomp.dcae.controller.service.docker.DockerServiceInstance; +import org.openecomp.dcae.controller.service.docker.host.servers.manager.DcaeDockerHostManager; +import org.openecomp.dcae.controller.service.docker.host.servers.manager.DcaeDockerHostManagerConsole; +import org.openecomp.dcae.controller.service.docker.host.servers.service.DcaeDockerHostService; +import org.openecomp.dcae.controller.service.docker.host.servers.service.DcaeDockerHostServiceProvider; +import org.openecomp.dcae.controller.service.docker.host.service.DockerHostServiceInstance; +import org.openecomp.dcae.controller.service.servers.dockermanager.DcaeDockerManagerConsole; +import org.openecomp.dcae.controller.service.servers.vmmanager.DcaeVirtualMachineManagerConsole; +import org.openecomp.dcae.controller.service.vm.VirtualMachineServiceInstance; +import org.openecomp.ncomp.core.DeploymentStatus; +import org.openecomp.ncomp.docker.ContainerOptions; +import org.openecomp.ncomp.docker.ContainerPortBindings; +import org.openecomp.ncomp.docker.DockerContainer; +import org.openecomp.ncomp.docker.DockerFactory; +import org.openecomp.ncomp.servers.docker.DockerDockerHostConsole; +import org.openecomp.ncomp.sirius.manager.AbstractClient; +import org.openecomp.ncomp.sirius.manager.BasicAdaptorProvider; +import org.openecomp.ncomp.sirius.manager.ISiriusServer; +import org.openecomp.ncomp.sirius.manager.JavaHttpClient; +import org.openecomp.ncomp.sirius.manager.ManagementServer; +import org.openecomp.ncomp.sirius.manager.ManagementServerUtils; +import org.openecomp.ncomp.sirius.manager.Subject; +import org.openecomp.ncomp.sirius.manager.metrics.MetricStore; +import org.openecomp.ncomp.utils.CryptoUtils; + +public class DcaeDockerServiceProvider extends BasicAdaptorProvider { + private static final Logger logger = Logger.getLogger(DcaeDockerServiceProvider.class); + DockerService o; + + public DcaeDockerServiceProvider(ISiriusServer controller, DockerService o) { + super(controller, o); + this.o = o; + } + + public void deploy(String instanceName, String containerPath) { + DockerServiceInstance i = findInstance(instanceName); + if (!(containerPath == null || containerPath.equals(""))) { + Subject s = controller.getServer().find(containerPath); + if (s == null || s.o == null) { + throw new RuntimeException("Unable to find container object: " + containerPath); + } + if (!(s.o instanceof DockerHostServiceInstance)) + throw new RuntimeException("Unable to deploy to this container: " + s.o); + i.setHostService((DockerHostServiceInstance) s.o); + } + if (i.getHostService() == null) { + throw new RuntimeException("Null Container: unable to deploy: " + o.getName() + " " + i.getName()); + } + i.setDockerName(dockerName(i)); + ContainerOptions opts = DockerFactory.eINSTANCE.createContainerOptions(); + opts.setName(i.getDockerName()); + opts.getVolumes().addAll(i.getVolumes()); + opts.getLinks().addAll(i.getLinks()); + opts.getEnv().addAll(i.getEnvs()); + for (ContainerPortBindings p : i.getPortBindings()) { + opts.getPortBindings().add(EcoreUtil.copy(p)); + } + console(instanceName).setupConfiguration(o.getName(), instanceName); + consoleHost(i).dockerRunWithOptions("/resources/dockerHost", image(i), opts); + long toolate = System.currentTimeMillis() + 2 * 60 * 1000; + // if has manager wait 2 minutes for container manager + while (i.getManagerPortNumber() > 0 && System.currentTimeMillis() < toolate) { + try { + o.pushManagerConfiguration(instanceName); + break; + } catch (Exception e) { + try { + Thread.sleep(5000); + } catch (InterruptedException e1) { + throw new RuntimeException("Deployment timeout: Deployment interrupted"); + } + } + if (System.currentTimeMillis() >= toolate) + throw new RuntimeException("Unable to configure Docker"); + } + } + + private String image(DockerServiceInstance i) { + if (i.getImage().contains("/")) + return i.getImage(); + String dns = i.getHostService().getServers().get(0).getNetworks().get(0).getDnsName(); + return dns + ":7113/" + i.getImage(); + } + + public void undeploy(String instanceName) { + DockerServiceInstance i = findInstance(instanceName); + DockerDockerHostConsole c = consoleHost(i); +// c.stopContainer("/resources/dockerHost", i.getDockerName(), 10); +// c.killContainer("/resources/dockerHost", i.getDockerName(), "KILL"); + c.removeContainer("/resources/dockerHost", i.getDockerName(), true, true); + } + + private DcaeDockerHostManagerConsole console(String instanceName) { + DockerServiceInstance i = findInstance(instanceName); + return new DcaeDockerHostManagerConsole(getClient(i)); + } + + public AbstractClient getClient(DockerServiceInstance i) { + DockerHostServiceInstance instance = i.getHostService(); + DcaeDockerHostService service = (DcaeDockerHostService) instance.getService(); + DcaeDockerHostServiceProvider provider = service.getSomfProvider(); + return provider.getClient(instance); + } + + private DockerDockerHostConsole consoleHost(DockerServiceInstance i) { + DockerHostServiceInstance instance = i.getHostService(); + DcaeDockerHostService service = (DcaeDockerHostService) instance.getService(); + DcaeDockerHostServiceProvider provider = service.getSomfProvider(); + AbstractClient c = provider.getClient(instance); + return new DockerDockerHostConsole(c); + } + + private String dockerName(DockerServiceInstance i) { + return "dcae_" + o.getName() + "_" + i.getName(); + // return "dcae"+ new Date().getTime(); + } + + protected DockerServiceInstance findInstance(String instanceName) { + for (DockerServiceInstance ii : o.getInstances()) { + if (ii.getName().equals(instanceName)) { + ii.setDockerName(dockerName(ii)); + return ii; + } + } + throw new RuntimeException("Unable to find instance: " + instanceName); + + } + + public HealthTestResponse test(String instanceName) { + DockerServiceInstance i = findInstance(instanceName); + DockerContainer c = findContainer(i); + HealthTestResponse h = ServiceFactory.eINSTANCE.createHealthTestResponse(); + if (c == null) { + h.setStatus(HealthTestStatus.YELLOW); + h.setMessageCode("Container not Deployed"); + return h; + } + System.out.println("DOCKER: test" + i.getDockerName() + " " + c.getStatus()); + if (c.getStatus().startsWith("Exited")) { + h.setStatus(HealthTestStatus.RED); + h.setMessageCode("Container not running"); + return h; + } + if (c.getStatus().startsWith("Created")) { + h.setStatus(HealthTestStatus.RED); + h.setMessageCode("Container never started"); + return h; + } + if (c.getStatus().startsWith("Restarting")) { + h.setStatus(HealthTestStatus.RED); + h.setMessageCode("Container restarting"); + return h; + } + if (i.getManagerPortNumber() > 0) { + System.out.println("DOCKER: test" + i.getDockerName() + "HERE"); + return console(instanceName).testContainer(i.getDockerName()); + } + h.setStatus(HealthTestStatus.GREEN); + return h; + } + + public void suspend(String instanceName) { + DockerServiceInstance i = findInstance(instanceName); + console(instanceName).suspendContainer(i.getDockerName()); + } + + public void resume(String instanceName) { + DockerServiceInstance i = findInstance(instanceName); + console(instanceName).resumeContainer(i.getDockerName()); + } + + public void pushManagerConfiguration(String instanceName) { + DockerServiceInstance i = findInstance(instanceName); + DcaeDockerHostManagerConsole console = console(instanceName); + EObject config = o.managerConfiguration(instanceName); + System.out.println("DDDDD " + ManagementServer.ecore2json(config, 1000, null, true).toString(2)); + EList<DcaeStream> l1 = new BasicEList<DcaeStream>(); + l1.addAll(EcoreUtil.copyAll(i.getInputStreams())); + EList<DcaeStream> l2 = new BasicEList<DcaeStream>(); + l2.addAll(EcoreUtil.copyAll(i.getOutputStreams())); + console.updateContainerConfiguration(i.getDockerName(), config, decrypt(l1), decrypt(l2)); + } + + private EList<DcaeStream> decrypt(EList<DcaeStream> l) { + for (DcaeStream s : l) { + if (s instanceof DmaapStream) { + DmaapStream s1 = (DmaapStream) s; + String pw = s1.getDmaapPassword(); + if (pw != null && pw.startsWith("rsa:")) { + try { + s1.setDmaapPassword(JavaHttpClient.decryptPassword(pw)); + } catch (Exception e) { + System.err.println("ZZZZZ: bad pw: " + ManagementServer.object2ref(s)); + s1.setDmaapPassword("decryption error"); + } + } + else + System.err.println("ZZZZZ: unencrypted pw: " + ManagementServer.object2ref(s)); + continue; + } + System.err.println("ZZZZZ: unknown type: " + s); + } + return l; + } + + public void pollManagerConfiguration(String instanceName) { + + // TODO IMPLEMENT + throw new UnsupportedOperationException(); + } + + public org.eclipse.emf.ecore.EObject managerConfiguration(String instanceName) { + // TODO IMPLEMENT + throw new UnsupportedOperationException(); + } + + public JSONObject managerOperation(String instanceName, String operation, JSONObject parameters) { + // TODO IMPLEMENT + throw new UnsupportedOperationException(); + } + + public void updateConfigurationFromPolicy(String instanceName) { + + // TODO IMPLEMENT + throw new UnsupportedOperationException(); + } + + public void runHealthTests() { + System.out.println("DOCKER: runHealthTests" + o.getName()); + for (DockerServiceInstance i : o.getInstances()) { + HealthTestResponse s = null; + try { + s = o.test(i.getName()); + } catch (Exception e) { + s = ServiceFactory.eINSTANCE.createHealthTestResponse(); + s.setMessageCode("Unable to determine health: " + e); + s.setStatus(HealthTestStatus.RED); + } + i.setHealthTestStatus(s.getStatus()); + i.setHealthTestMessageCode(s.getMessageCode()); + MetricStore store = controller.getServer().metrics.getStore(i); + Date now = new Date(); + String path = "/lastHealthTest"; + store.addLongValue(path, now, now.getTime(), "DateMetricAttribute", false); + } + } + + public void start() { + + Thread t = new Thread("docker service: " + o.getName()) { + @Override + public void run() { + while (true) { + try { + if (! controller.getServer().isSlave) + updateDeploymentStatus(); + Thread.sleep(60000); // sleep 60 seconds + } catch (Exception e) { + ManagementServerUtils.printStackTrace(e); + logger.fatal("vm service: " + o.getName() + " : " + e); + try { + Thread.sleep(30000); + } catch (InterruptedException e1) { + } + } + } + } + + }; + t.start(); + } + + public void updateDeploymentStatus() { + for (DockerServiceInstance instance : o.getInstances()) { + instance.setDockerName(dockerName(instance)); + DockerContainer c = findContainer(instance); + if (c != null) { + if (c.getStatus() != null && c.getStatus().startsWith("Up")) + instance.setStatus(DeploymentStatus.DEPLOYED); + else + instance.setStatus(DeploymentStatus.DEPLOYED_PARTIALLY); + } + else + instance.setStatus(DeploymentStatus.UNDEPLOYED); + } + } + + private DockerContainer findContainer(DockerServiceInstance instance) { + if (instance.getHostService() == null) + return null; + for (DockerContainer c : instance.getHostService().getDockerHost().getContainers()) { + if (instance.getDockerName() != null && instance.getDockerName().equals(c.getName())) { + return c; + } + } + return null; + } + + protected EObject convertToManagerConfiguration(DockerServiceInstance i) { + // TODO Auto-generated method stub + return null; + } +} diff --git a/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/servers/dockermanager/DcaeDockerManagerProvider.java b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/servers/dockermanager/DcaeDockerManagerProvider.java new file mode 100644 index 0000000..a6e70da --- /dev/null +++ b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/servers/dockermanager/DcaeDockerManagerProvider.java @@ -0,0 +1,172 @@ + +/*- + * ============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.dcae.controller.service.servers.dockermanager; + + + + + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStreamWriter; +import java.util.Date; + +import org.openecomp.ncomp.sirius.manager.IRequestHandler; +import org.openecomp.ncomp.sirius.manager.ISiriusPlugin; +import org.openecomp.ncomp.sirius.manager.ISiriusServer; +import org.openecomp.ncomp.sirius.manager.ManagementServer; +import org.openecomp.ncomp.sirius.manager.ManagementServerUtils; +import org.openecomp.ncomp.sirius.function.FunctionUtils; + +import org.apache.log4j.Logger; +import org.eclipse.emf.common.util.EList; +import org.json.JSONArray; +import org.json.JSONObject; + + + + +import org.openecomp.ncomp.sirius.manager.BasicAdaptorProvider; +import org.openecomp.ncomp.webservice.utils.FileUtils; +import org.openecomp.dcae.controller.core.service.HealthTestResponse; +import org.openecomp.dcae.controller.core.service.HealthTestStatus; +import org.openecomp.dcae.controller.core.service.ServiceFactory; +import org.openecomp.dcae.controller.core.stream.DcaeStream; +import org.openecomp.dcae.controller.service.dockermanager.impl.DockerManagerImpl; +import org.openecomp.dcae.controller.service.dockermanager.DockerManager; + + +public class DcaeDockerManagerProvider extends BasicAdaptorProvider { + private static final Logger logger = Logger.getLogger(DcaeDockerManagerProvider.class); + DockerManager o; + private boolean suspended; + + public DcaeDockerManagerProvider(ISiriusServer controller, DockerManager o) { + super(controller, o); + this.o = o; + } + + public HealthTestResponse test() { + HealthTestResponse res = ServiceFactory.eINSTANCE.createHealthTestResponse(); + res.setStatus(HealthTestStatus.GREEN); + return res; + } + + public void suspend() { + suspended = true; + } + + public void resume() { + suspended = false; + } + + public java.lang.String publicKey() { + throw new UnsupportedOperationException(); + } + + // US618656 + public void configurationChanged() { + updateDMaapConfig(); + } + + // US618665 + private void updateDMaapConfig() { + JSONArray a = new JSONArray(); + for (DcaeStream s : o.getInputStreams()) { + JSONObject json = ManagementServer.ecore2json(s, 100, null, true); + json.put("dmaapStreamId", s.getName()); + a.put(json); + } + for (DcaeStream s : o.getOutputStreams()) { + JSONObject json = ManagementServer.ecore2json(s, 100, null, true); + json.put("dmaapStreamId", s.getName()); + a.put(json); + } + write2file(a,"/tmp/dmaap.conf2"); + write2file(a,"/etc/dcae/dmaap.conf"); + + } + + private void write2file(JSONArray a, String fileName) { + try { + OutputStreamWriter w = FileUtils.filename2writer(fileName); + w.write(a.toString(2)); + w.close(); + } catch (Exception e) { + logger.warn("Unable to write file: " + fileName); + ManagementServerUtils.printStackTrace(e); + } + } + + public void updateStreams(EList<DcaeStream> inputStreams, EList<DcaeStream> outputStreams) { + o.getInputStreams().clear(); + o.getInputStreams().addAll(inputStreams); + o.getOutputStreams().clear(); + o.getOutputStreams().addAll(outputStreams); + } + + public void scheduleCronjob(final String cmd, final long frequency) { + Thread t = new Thread("crontab: " + cmd) { + @Override + public void run() { + while (true) { + try { + Date now = new Date(); + long wait = frequency - (now.getTime() % frequency); + Thread.sleep(wait); + if (suspended) continue; + Runtime runtime = Runtime.getRuntime(); + Process proc; + try { + now = new Date(); + proc = runtime.exec(cmd); + ByteArrayOutputStream o = new ByteArrayOutputStream(); + ByteArrayOutputStream e = new ByteArrayOutputStream(); + FileUtils.copyStream(proc.getInputStream(), o); + FileUtils.copyStream(proc.getErrorStream(), e); + int i = proc.waitFor(); + if (i != 0) + logger.warn("crontab return error: " + cmd + " " + i); + long duration = new Date().getTime()-now.getTime(); + if (duration > frequency) + logger.warn("crontab took too long: " + cmd + " " + duration); + } catch (Exception e) { + e.printStackTrace(); + logger.warn("ERROR: " + e); + } + } catch (Exception e) { + ManagementServerUtils.printStackTrace(e); + logger.fatal("crontab: " + cmd + " " + e); + try { + Thread.sleep(30000); + } catch (InterruptedException e1) { + } + } + } + }; + }; + t.start(); + } + + +} diff --git a/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/servers/dockermanager/gui/DcaeGuiClientApiProvider.java b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/servers/dockermanager/gui/DcaeGuiClientApiProvider.java new file mode 100644 index 0000000..4ac1e4e --- /dev/null +++ b/dcae-controller-service-docker/dcae-controller-service-docker-adaptor/src/main/java/org/openecomp/dcae/controller/service/servers/dockermanager/gui/DcaeGuiClientApiProvider.java @@ -0,0 +1,78 @@ + +/*- + * ============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.dcae.controller.service.servers.dockermanager.gui; + + + + + +import java.io.InputStream; + +import org.openecomp.ncomp.sirius.manager.IRequestHandler; +import org.openecomp.ncomp.sirius.manager.ISiriusPlugin; +import org.openecomp.ncomp.sirius.manager.ISiriusServer; +import org.openecomp.ncomp.sirius.function.FunctionUtils; + +import org.apache.log4j.Logger; +import org.eclipse.emf.common.util.EList; +import org.json.JSONObject; + + + +import org.openecomp.ncomp.sirius.gui.tools.*; + + +import org.openecomp.ncomp.gwt.siriusportal.model.*; + + +import org.openecomp.ncomp.sirius.manager.Subject; + + +import org.openecomp.ncomp.sirius.manager.ManagementServer; + + +import org.openecomp.ncomp.sirius.manager.server.AbstractManagementServer; + + +import org.openecomp.ncomp.sirius.manager.BasicGuiClientApiProvider; + + +import org.openecomp.ncomp.gwt.siriusportal.model.impl.GuiClientApiImpl; +import org.openecomp.ncomp.gwt.siriusportal.model.GuiClientApi; + + +public class DcaeGuiClientApiProvider extends BasicGuiClientApiProvider { + private static final Logger logger = Logger.getLogger(DcaeGuiClientApiProvider.class); + GuiClientApi o; + + public DcaeGuiClientApiProvider(ISiriusServer controller, GuiClientApi o) { + super(controller, o); + this.o = o; + } + + + + + + +} |