001/* 002 * (C) Copyright 2006-2017 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Tiago Cardoso <[email protected]> 018 */ 019package org.nuxeo.ecm.platform.threed.convert; 020 021import org.nuxeo.ecm.platform.commandline.executor.api.CmdParameters; 022import org.nuxeo.ecm.platform.commandline.executor.api.CommandLineExecutorService; 023import org.nuxeo.ecm.platform.commandline.executor.api.CommandNotAvailable; 024import org.nuxeo.ecm.platform.commandline.executor.api.ExecResult; 025import org.nuxeo.runtime.api.Framework; 026 027/** 028 * Helper class to get java runtime owner user id 029 * 030 * @since 8.10 031 */ 032public class DockerHelper { 033 034 public static final String CREATE_CONTAINER_COMMAND = "create_container"; 035 036 public static final String REMOVE_CONTAINER_COMMAND = "remove_container"; 037 038 public static final String COPY_CONTAINER_COMMAND = "copy_container"; 039 040 public static final String NAME_PARAM = "name"; 041 042 public static final String IMAGE_PARAM = "image"; 043 044 public static final String SOURCE_PARAM = "source"; 045 046 public static final String DEST_PARAM = "destination"; 047 048 public static ExecResult CreateContainer(String name, String image) { 049 CmdParameters params = new CmdParameters(); 050 params.addNamedParameter(NAME_PARAM, name); 051 params.addNamedParameter(IMAGE_PARAM, image); 052 return executeCommand(CREATE_CONTAINER_COMMAND, params); 053 } 054 055 public static ExecResult RemoveContainer(String name) { 056 CmdParameters params = new CmdParameters(); 057 params.addNamedParameter(NAME_PARAM, name); 058 return executeCommand(REMOVE_CONTAINER_COMMAND, params); 059 } 060 061 public static ExecResult CopyData(String source, String destination) { 062 CmdParameters params = new CmdParameters(); 063 params.addNamedParameter(SOURCE_PARAM, source); 064 params.addNamedParameter(DEST_PARAM, destination); 065 return executeCommand(COPY_CONTAINER_COMMAND, params); 066 } 067 068 private static ExecResult executeCommand(String command, CmdParameters params) { 069 ExecResult result = null; 070 try { 071 result = Framework.getService(CommandLineExecutorService.class).execCommand(command, params); 072 } catch (CommandNotAvailable commandNotAvailable) { 073 return null; 074 } 075 return result; 076 } 077 078}