├── .gitignore
├── README.md
├── mvnw
├── mvnw.cmd
├── pom.xml
└── src
├── main
├── java
│ └── com
│ │ └── icnslab
│ │ ├── ContainerCreator.java
│ │ ├── EtcdConnector.java
│ │ ├── HpcController.java
│ │ ├── HpcService.java
│ │ ├── KistiApplication.java
│ │ ├── assist
│ │ ├── JSONAssistant.java
│ │ └── WebConfig.java
│ │ ├── database
│ │ └── PlatformDao.java
│ │ ├── message
│ │ ├── Container.java
│ │ ├── ContainerBuilder.java
│ │ ├── ContainerCommitResponse.java
│ │ ├── ContainerCreationResponse.java
│ │ ├── ContainerDeleteResponse.java
│ │ ├── Image.java
│ │ ├── JobContainer.java
│ │ ├── JobMessage.java
│ │ └── User.java
│ │ └── mpiSetter
│ │ ├── MpiSetter.java
│ │ └── MpichSetter.java
└── resources
│ └── application.properties
└── test
└── java
└── com
└── icnslab
└── KistiApplicationTests.java
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | !.mvn/wrapper/maven-wrapper.jar
3 | keys
4 | ### STS ###
5 | .apt_generated
6 | .classpath
7 | .factorypath
8 | .project
9 | .settings
10 | .springBeans
11 |
12 | ### IntelliJ IDEA ###
13 | .idea
14 | *.iws
15 | *.iml
16 | *.ipr
17 |
18 | ### NetBeans ###
19 | nbproject/private/
20 | build/
21 | nbbuild/
22 | dist/
23 | nbdist/
24 | .nb-gradle/
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HPC_API_server
2 |
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # http://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven2 Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /etc/mavenrc ] ; then
40 | . /etc/mavenrc
41 | fi
42 |
43 | if [ -f "$HOME/.mavenrc" ] ; then
44 | . "$HOME/.mavenrc"
45 | fi
46 |
47 | fi
48 |
49 | # OS specific support. $var _must_ be set to either true or false.
50 | cygwin=false;
51 | darwin=false;
52 | mingw=false
53 | case "`uname`" in
54 | CYGWIN*) cygwin=true ;;
55 | MINGW*) mingw=true;;
56 | Darwin*) darwin=true
57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
59 | if [ -z "$JAVA_HOME" ]; then
60 | if [ -x "/usr/libexec/java_home" ]; then
61 | export JAVA_HOME="`/usr/libexec/java_home`"
62 | else
63 | export JAVA_HOME="/Library/Java/Home"
64 | fi
65 | fi
66 | ;;
67 | esac
68 |
69 | if [ -z "$JAVA_HOME" ] ; then
70 | if [ -r /etc/gentoo-release ] ; then
71 | JAVA_HOME=`java-config --jre-home`
72 | fi
73 | fi
74 |
75 | if [ -z "$M2_HOME" ] ; then
76 | ## resolve links - $0 may be a link to maven's home
77 | PRG="$0"
78 |
79 | # need this for relative symlinks
80 | while [ -h "$PRG" ] ; do
81 | ls=`ls -ld "$PRG"`
82 | link=`expr "$ls" : '.*-> \(.*\)$'`
83 | if expr "$link" : '/.*' > /dev/null; then
84 | PRG="$link"
85 | else
86 | PRG="`dirname "$PRG"`/$link"
87 | fi
88 | done
89 |
90 | saveddir=`pwd`
91 |
92 | M2_HOME=`dirname "$PRG"`/..
93 |
94 | # make it fully qualified
95 | M2_HOME=`cd "$M2_HOME" && pwd`
96 |
97 | cd "$saveddir"
98 | # echo Using m2 at $M2_HOME
99 | fi
100 |
101 | # For Cygwin, ensure paths are in UNIX format before anything is touched
102 | if $cygwin ; then
103 | [ -n "$M2_HOME" ] &&
104 | M2_HOME=`cygpath --unix "$M2_HOME"`
105 | [ -n "$JAVA_HOME" ] &&
106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
107 | [ -n "$CLASSPATH" ] &&
108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
109 | fi
110 |
111 | # For Migwn, ensure paths are in UNIX format before anything is touched
112 | if $mingw ; then
113 | [ -n "$M2_HOME" ] &&
114 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
115 | [ -n "$JAVA_HOME" ] &&
116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
117 | # TODO classpath?
118 | fi
119 |
120 | if [ -z "$JAVA_HOME" ]; then
121 | javaExecutable="`which javac`"
122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
123 | # readlink(1) is not available as standard on Solaris 10.
124 | readLink=`which readlink`
125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
126 | if $darwin ; then
127 | javaHome="`dirname \"$javaExecutable\"`"
128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
129 | else
130 | javaExecutable="`readlink -f \"$javaExecutable\"`"
131 | fi
132 | javaHome="`dirname \"$javaExecutable\"`"
133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
134 | JAVA_HOME="$javaHome"
135 | export JAVA_HOME
136 | fi
137 | fi
138 | fi
139 |
140 | if [ -z "$JAVACMD" ] ; then
141 | if [ -n "$JAVA_HOME" ] ; then
142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
143 | # IBM's JDK on AIX uses strange locations for the executables
144 | JAVACMD="$JAVA_HOME/jre/sh/java"
145 | else
146 | JAVACMD="$JAVA_HOME/bin/java"
147 | fi
148 | else
149 | JAVACMD="`which java`"
150 | fi
151 | fi
152 |
153 | if [ ! -x "$JAVACMD" ] ; then
154 | echo "Error: JAVA_HOME is not defined correctly." >&2
155 | echo " We cannot execute $JAVACMD" >&2
156 | exit 1
157 | fi
158 |
159 | if [ -z "$JAVA_HOME" ] ; then
160 | echo "Warning: JAVA_HOME environment variable is not set."
161 | fi
162 |
163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
164 |
165 | # traverses directory structure from process work directory to filesystem root
166 | # first directory with .mvn subdirectory is considered project base directory
167 | find_maven_basedir() {
168 |
169 | if [ -z "$1" ]
170 | then
171 | echo "Path not specified to find_maven_basedir"
172 | return 1
173 | fi
174 |
175 | basedir="$1"
176 | wdir="$1"
177 | while [ "$wdir" != '/' ] ; do
178 | if [ -d "$wdir"/.mvn ] ; then
179 | basedir=$wdir
180 | break
181 | fi
182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
183 | if [ -d "${wdir}" ]; then
184 | wdir=`cd "$wdir/.."; pwd`
185 | fi
186 | # end of workaround
187 | done
188 | echo "${basedir}"
189 | }
190 |
191 | # concatenates all lines of a file
192 | concat_lines() {
193 | if [ -f "$1" ]; then
194 | echo "$(tr -s '\n' ' ' < "$1")"
195 | fi
196 | }
197 |
198 | BASE_DIR=`find_maven_basedir "$(pwd)"`
199 | if [ -z "$BASE_DIR" ]; then
200 | exit 1;
201 | fi
202 |
203 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
204 | echo $MAVEN_PROJECTBASEDIR
205 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
206 |
207 | # For Cygwin, switch paths to Windows format before running java
208 | if $cygwin; then
209 | [ -n "$M2_HOME" ] &&
210 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
211 | [ -n "$JAVA_HOME" ] &&
212 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
213 | [ -n "$CLASSPATH" ] &&
214 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
215 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
216 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
217 | fi
218 |
219 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
220 |
221 | exec "$JAVACMD" \
222 | $MAVEN_OPTS \
223 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
224 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
225 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
226 |
--------------------------------------------------------------------------------
/mvnw.cmd:
--------------------------------------------------------------------------------
1 | @REM ----------------------------------------------------------------------------
2 | @REM Licensed to the Apache Software Foundation (ASF) under one
3 | @REM or more contributor license agreements. See the NOTICE file
4 | @REM distributed with this work for additional information
5 | @REM regarding copyright ownership. The ASF licenses this file
6 | @REM to you under the Apache License, Version 2.0 (the
7 | @REM "License"); you may not use this file except in compliance
8 | @REM with the License. You may obtain a copy of the License at
9 | @REM
10 | @REM http://www.apache.org/licenses/LICENSE-2.0
11 | @REM
12 | @REM Unless required by applicable law or agreed to in writing,
13 | @REM software distributed under the License is distributed on an
14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 | @REM KIND, either express or implied. See the License for the
16 | @REM specific language governing permissions and limitations
17 | @REM under the License.
18 | @REM ----------------------------------------------------------------------------
19 |
20 | @REM ----------------------------------------------------------------------------
21 | @REM Maven2 Start Up Batch script
22 | @REM
23 | @REM Required ENV vars:
24 | @REM JAVA_HOME - location of a JDK home dir
25 | @REM
26 | @REM Optional ENV vars
27 | @REM M2_HOME - location of maven2's installed home dir
28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands
29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending
30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven
31 | @REM e.g. to debug Maven itself, use
32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files
34 | @REM ----------------------------------------------------------------------------
35 |
36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on'
37 | @echo off
38 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on'
39 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO%
40 |
41 | @REM set %HOME% to equivalent of $HOME
42 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%")
43 |
44 | @REM Execute a user defined script before this one
45 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre
46 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending
47 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat"
48 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd"
49 | :skipRcPre
50 |
51 | @setlocal
52 |
53 | set ERROR_CODE=0
54 |
55 | @REM To isolate internal variables from possible post scripts, we use another setlocal
56 | @setlocal
57 |
58 | @REM ==== START VALIDATION ====
59 | if not "%JAVA_HOME%" == "" goto OkJHome
60 |
61 | echo.
62 | echo Error: JAVA_HOME not found in your environment. >&2
63 | echo Please set the JAVA_HOME variable in your environment to match the >&2
64 | echo location of your Java installation. >&2
65 | echo.
66 | goto error
67 |
68 | :OkJHome
69 | if exist "%JAVA_HOME%\bin\java.exe" goto init
70 |
71 | echo.
72 | echo Error: JAVA_HOME is set to an invalid directory. >&2
73 | echo JAVA_HOME = "%JAVA_HOME%" >&2
74 | echo Please set the JAVA_HOME variable in your environment to match the >&2
75 | echo location of your Java installation. >&2
76 | echo.
77 | goto error
78 |
79 | @REM ==== END VALIDATION ====
80 |
81 | :init
82 |
83 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn".
84 | @REM Fallback to current working directory if not found.
85 |
86 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%
87 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir
88 |
89 | set EXEC_DIR=%CD%
90 | set WDIR=%EXEC_DIR%
91 | :findBaseDir
92 | IF EXIST "%WDIR%"\.mvn goto baseDirFound
93 | cd ..
94 | IF "%WDIR%"=="%CD%" goto baseDirNotFound
95 | set WDIR=%CD%
96 | goto findBaseDir
97 |
98 | :baseDirFound
99 | set MAVEN_PROJECTBASEDIR=%WDIR%
100 | cd "%EXEC_DIR%"
101 | goto endDetectBaseDir
102 |
103 | :baseDirNotFound
104 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR%
105 | cd "%EXEC_DIR%"
106 |
107 | :endDetectBaseDir
108 |
109 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig
110 |
111 | @setlocal EnableExtensions EnableDelayedExpansion
112 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a
113 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS%
114 |
115 | :endReadAdditionalConfig
116 |
117 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe"
118 |
119 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar"
120 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
121 |
122 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %*
123 | if ERRORLEVEL 1 goto error
124 | goto end
125 |
126 | :error
127 | set ERROR_CODE=1
128 |
129 | :end
130 | @endlocal & set ERROR_CODE=%ERROR_CODE%
131 |
132 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost
133 | @REM check for post script, once with legacy .bat ending and once with .cmd ending
134 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat"
135 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd"
136 | :skipRcPost
137 |
138 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
139 | if "%MAVEN_BATCH_PAUSE%" == "on" pause
140 |
141 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE%
142 |
143 | exit /B %ERROR_CODE%
144 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | com.icnslab
7 | kisti
8 | 0.0.1-SNAPSHOT
9 | jar
10 |
11 | kisti
12 | Kisti Restful API Server
13 |
14 |
15 | org.springframework.boot
16 | spring-boot-starter-parent
17 | 1.5.6.RELEASE
18 |
19 |
20 |
21 |
22 | UTF-8
23 | UTF-8
24 | 1.8
25 |
26 |
27 |
28 |
29 | org.springframework.boot
30 | spring-boot-starter-web
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-test
36 | test
37 |
38 |
39 |
40 | org.mousio
41 | etcd4j
42 | 2.13.0
43 |
44 |
45 |
46 | com.spotify
47 | docker-client
48 | 8.8.0
49 |
50 |
51 |
52 | mysql
53 | mysql-connector-java
54 | 5.1.34
55 |
56 |
57 | org.springframework.boot
58 | spring-boot-starter-jdbc
59 | 1.4.1.RELEASE
60 |
61 |
62 |
63 |
64 | com.googlecode.json-simple
65 | json-simple
66 | 1.1.1
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | org.springframework.boot
75 | spring-boot-maven-plugin
76 |
77 |
78 |
79 |
80 |
81 |
82 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/ContainerCreator.java:
--------------------------------------------------------------------------------
1 | package com.icnslab;
2 |
3 | import com.icnslab.message.Container;
4 | import com.icnslab.mpiSetter.MpichSetter;
5 | import com.spotify.docker.client.DockerClient;
6 | import com.spotify.docker.client.messages.ContainerConfig;
7 | import com.spotify.docker.client.messages.ContainerCreation;
8 | import com.spotify.docker.client.messages.HostConfig;
9 | import com.spotify.docker.client.messages.PortBinding;
10 |
11 | import java.util.ArrayList;
12 | import java.util.HashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | /**
17 | * Created by alicek106 on 2017-08-17.
18 | */
19 | public class ContainerCreator {
20 | // private static final String CENTOS_IMAGE_NAME = "601kecila/ssh-server-centos:0.0-devel-tools";
21 | private static final String CENTOS_IMAGE_NAME = "601kecila/ssh-server-centos7:0.1-tcconfig";
22 | private static final String UBUNTU_IMAGE_NAME = "601kecila/ssh-server-ubuntu14-04:0.0-tcconfig";
23 | private static final String[] AVAILABLE_PORT = {"50002","50003","50004"};
24 |
25 | public static String createContainer(DockerClient dc, Container container){
26 | // temp : MPICH
27 | List binds = null;
28 | if(container.getMpilib().contains("mpich")){
29 | MpichSetter mpichSetter = new MpichSetter();
30 | binds = mpichSetter.setMpiBind(container);
31 | }
32 |
33 | final String[] ports = {"22"};
34 | final Map> portBindings = new HashMap<>();
35 | for (String port : ports) {
36 | List hostPorts = new ArrayList<>();
37 | hostPorts.add(PortBinding.create("0.0.0.0", AVAILABLE_PORT[0]));//randomPort("0.0.0.0"));
38 | portBindings.put(port, hostPorts);
39 | }
40 |
41 | final HostConfig hostConfig = HostConfig.builder().
42 | portBindings(portBindings).
43 | binds(binds).
44 | build();
45 |
46 | String image = (container.getBaseimage().equals("centos")?CENTOS_IMAGE_NAME:UBUNTU_IMAGE_NAME);
47 |
48 | // Create container with exposed ports
49 | final ContainerConfig containerConfig = ContainerConfig.builder()
50 | .hostConfig(hostConfig)
51 | .image(image)
52 | .hostname(container.getName())
53 | .tty(true)
54 | .openStdin(true).exposedPorts(ports)
55 | .build();
56 |
57 | try {
58 | final ContainerCreation creation = dc.createContainer(containerConfig, container.getUser() + "-" + container.getName());
59 | final String id = creation.id();
60 |
61 | // Start container
62 | dc.startContainer(id);
63 | return id;
64 | }
65 | catch(Exception e){
66 | e.printStackTrace();
67 | return null;
68 | }
69 |
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/EtcdConnector.java:
--------------------------------------------------------------------------------
1 | package com.icnslab;
2 |
3 | import mousio.etcd4j.EtcdClient;
4 | import mousio.etcd4j.promises.EtcdResponsePromise;
5 | import mousio.etcd4j.responses.EtcdKeysResponse;
6 | import org.springframework.stereotype.Component;
7 | import org.springframework.stereotype.Repository;
8 | import org.springframework.stereotype.Service;
9 |
10 | import java.io.IOException;
11 | import java.net.URI;
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | /**
16 | * Created by alicek106 on 2017-08-03.
17 | */
18 |
19 | public class EtcdConnector {
20 | private EtcdClient etcd;
21 |
22 | @SuppressWarnings("deprecation")
23 | public EtcdConnector() {
24 | etcd = new EtcdClient(URI.create("http://163.180.117.68:2379"), URI.create("http://163.180.117.68:2379"));
25 | System.out.println(etcd.getVersion());
26 | }
27 |
28 | public List listNode(String nodePath){
29 | List list = new ArrayList();
30 |
31 | try{
32 | EtcdResponsePromise node = etcd.get(nodePath).send();
33 | List etcdNodeList = node.get().node.getNodes();
34 | for(EtcdKeysResponse.EtcdNode etcdNode : etcdNodeList){
35 | list.add(etcdNode.key);
36 | }
37 | }
38 | catch(Exception e){
39 | e.printStackTrace();
40 | }
41 |
42 | return list;
43 | }
44 |
45 | public List getWorkerAddr(){
46 | List nodeList = listNode("/docker/nodes");
47 | List newList = new ArrayList();
48 |
49 | for(String str : nodeList){
50 | newList.add("https://" + str.split("/")[3].replace("10.", "163."));
51 | }
52 |
53 | return newList;
54 | }
55 |
56 | public String getBuilderAddr(){
57 | return getValue("/nodes/builder");
58 | }
59 | public String getRegistryAddr(){return getValue("/nodes/registry");}
60 |
61 | private String getValue(String keyPath) {
62 | try {
63 | EtcdResponsePromise node = etcd.get(keyPath).send();
64 | return node.get().node.getValue();
65 | }
66 |
67 | catch (Exception e) {
68 | e.printStackTrace();
69 | return "";
70 | }
71 | }
72 |
73 | public void closeConnection() {
74 | try {
75 | etcd.close();
76 | } catch (IOException e) {
77 | e.printStackTrace();
78 | }
79 | }
80 |
81 | /*
82 | public static void main(String[] args) {
83 | EtcdConnector etcd = new EtcdConnector();
84 | System.out.println(etcd.getValue("/nodes/builder"));
85 | System.out.println(etcd.getWorkerAddr());
86 | etcd.closeConnection();
87 | }*/
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/HpcController.java:
--------------------------------------------------------------------------------
1 | package com.icnslab;
2 |
3 | import com.icnslab.database.PlatformDao;
4 | import com.icnslab.message.*;
5 | import com.icnslab.message.Container;
6 | import com.spotify.docker.client.DefaultDockerClient;
7 | import com.spotify.docker.client.DockerCertificates;
8 | import com.spotify.docker.client.DockerClient;
9 | import org.json.simple.JSONObject;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.web.bind.annotation.*;
12 |
13 | import java.awt.*;
14 | import java.nio.file.Paths;
15 | import java.util.List;
16 |
17 | /**
18 | * Created by alicek106 on 2017-08-03.
19 | */
20 | @CrossOrigin(origins = "*")
21 | @RestController
22 | public class HpcController {
23 |
24 | @Autowired
25 | PlatformDao platformDao;
26 |
27 | @Autowired
28 | HpcService hpcService;
29 |
30 | @RequestMapping(value = "/api/build/container", method = RequestMethod.POST)
31 | @ResponseBody
32 | public ContainerCreationResponse createBuildContainer(@RequestParam(value = "uid", required = true) String uid,
33 | @RequestParam(value = "containerName", required = true) String containerName,
34 | @RequestParam(value = "mpiVersion", required = true) String mpiVersion,
35 | @RequestParam(value = "baseImage", required = true) String baseImage) {
36 | Container container = new ContainerBuilder().
37 | setMpilib(mpiVersion).
38 | setName(containerName).
39 | setUser(uid).
40 | setBaseImage(baseImage).
41 | createContainer();
42 | return hpcService.createBuildContainer(container);
43 | }
44 |
45 | @RequestMapping(value = "/api/build/container", method = RequestMethod.DELETE)
46 | @ResponseBody
47 | public ContainerDeleteResponse deleteBuildContainer(@RequestParam(value = "uid", required = true) String uid,
48 | @RequestParam(value = "containerName", required = true) String containerName){
49 | Container container = new ContainerBuilder().
50 | setName(containerName).
51 | setUser(uid).
52 | createContainer();
53 |
54 | return hpcService.deleteBuildContianer(container);
55 | }
56 |
57 | @RequestMapping(value = "/api/build/container", method = RequestMethod.GET)
58 | @ResponseBody
59 | public List getContainer(
60 | @RequestParam(value = "uid", required = true) String uid){
61 | return platformDao.selectContainer(uid);
62 | }
63 |
64 | @RequestMapping(value = "/api/build/commit", method = RequestMethod.POST)
65 | @ResponseBody
66 | public ContainerCommitResponse commitBuildContainer(
67 | @RequestParam(value = "containerName", required = true) String containerName,
68 | @RequestParam(value = "uid", required = true) String uid,
69 | @RequestParam(value = "imageName", required = true) String imageName,
70 | @RequestParam(value = "tag", required = true) String tag,
71 | @RequestParam(value = "metadata", required = true) String metadata,
72 | @RequestParam(value = "baseimage", required = true) String baseimage){
73 | return hpcService.commitContainer(containerName, imageName, tag, uid, metadata, baseimage);
74 | }
75 |
76 | @RequestMapping(value = "/api/build/distribute", method = RequestMethod.POST)
77 | @ResponseBody
78 | public ContainerCommitResponse distributeImage(
79 | @RequestParam(value = "imageName", required = true) String imageName,
80 | @RequestParam(value = "uid", required = true) String uid){
81 | System.out.println("starting distribute.. : " + uid + " " + imageName);
82 | return hpcService.distributeImage(imageName, uid);
83 | }
84 |
85 | @RequestMapping(value = "/api/build/image", method = RequestMethod.GET)
86 | @ResponseBody
87 | public List getImages(
88 | @RequestParam(value = "uid", required = true) String uid){
89 | return platformDao.selectImage(uid);
90 | }
91 |
92 | @RequestMapping(value = "/api/job/container", method = RequestMethod.GET)
93 | @ResponseBody
94 | public List getJobContainer(
95 | @RequestParam(value = "uid", required = true) String uid){
96 | return platformDao.selectJobContainer(uid);
97 | }
98 |
99 | @RequestMapping(value = "/api/job/metrics", method = RequestMethod.GET)
100 | @ResponseBody
101 | public String getJobMetrics(
102 | @RequestParam(value = "uid", required = true) String uid){
103 |
104 | JSONObject data = hpcService.getMetrics(uid);
105 | return data.toJSONString();
106 | }
107 | }
108 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/HpcService.java:
--------------------------------------------------------------------------------
1 | package com.icnslab;
2 |
3 | import com.icnslab.database.PlatformDao;
4 | import com.icnslab.message.*;
5 | import com.spotify.docker.client.*;
6 | import com.spotify.docker.client.exceptions.DockerException;
7 | import com.spotify.docker.client.messages.*;
8 | import org.json.simple.JSONObject;
9 | import org.jvnet.hk2.annotations.Service;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 | import org.springframework.stereotype.Repository;
12 |
13 | import java.nio.file.Paths;
14 | import java.text.SimpleDateFormat;
15 | import java.util.*;
16 |
17 | /**
18 | * Created by alicek106 on 2017-08-03.
19 | */
20 | @Repository
21 | public class HpcService {
22 |
23 | @Autowired
24 | PlatformDao platformDao;
25 |
26 | private EtcdConnector etcdConnector = new EtcdConnector();
27 |
28 | public ContainerDeleteResponse deleteBuildContianer(com.icnslab.message.Container container){
29 | ContainerDeleteResponse containerDeleteResponse = new ContainerDeleteResponse();
30 | containerDeleteResponse.setUserUid(container.getUser());
31 |
32 | DockerClient builderDockerClient = new DefaultDockerClient(etcdConnector.getBuilderAddr());
33 | try {
34 | builderDockerClient.removeContainer(container.getUser() + "-" + container.getName(), DockerClient.RemoveContainerParam.forceKill());
35 | platformDao.deleteContainer(container.getName(), container.getUser());
36 | containerDeleteResponse.setResponseCode(0);
37 | }catch(Exception e) {
38 | e.printStackTrace();
39 | containerDeleteResponse.setResponseCode(-1);
40 | }
41 |
42 | return containerDeleteResponse;
43 | }
44 |
45 | public ContainerCreationResponse createBuildContainer(com.icnslab.message.Container container){
46 | ContainerCreationResponse containerCreationResponse = new ContainerCreationResponse();
47 | containerCreationResponse.setUserUid(container.getUser());
48 |
49 | DockerClient builderDockerClient = new DefaultDockerClient(etcdConnector.getBuilderAddr());
50 | String containerId = ContainerCreator.createContainer(builderDockerClient, container);
51 |
52 | if(containerId == null){
53 | containerCreationResponse.setResponseCode(-1);
54 | }else {
55 | String key = getPrivateKey(containerId, builderDockerClient);
56 |
57 | containerCreationResponse.setAccessUrl("163.180.117.219:50002");
58 | containerCreationResponse.setSecretAccessKey(key);
59 | containerCreationResponse.setResponseCode(0);
60 |
61 | container.setServer("163.180.117.219:50002");
62 | container.setCreated(getCurrentDate());
63 | platformDao.insertContainer(container);
64 | }
65 |
66 | builderDockerClient.close();
67 | return containerCreationResponse;
68 | }
69 |
70 | public ContainerCommitResponse commitContainer(String containerName, String imageName, String tag, String uid, String metadata, String baseimage){
71 | ContainerCommitResponse containerCommitResponse = new ContainerCommitResponse();
72 | DockerClient builderDockerClient = new DefaultDockerClient(etcdConnector.getBuilderAddr());
73 | //String containerId = platformDao.selectContainerId(uid);
74 |
75 | String fullImageName = commitContainer(uid + "-" + containerName, imageName, tag, uid, builderDockerClient);
76 |
77 | if(fullImageName == null){
78 | containerCommitResponse.setResponseCode(-1);
79 | }
80 | else {
81 | containerCommitResponse.setImageName(fullImageName);
82 | containerCommitResponse.setUserUid(uid);
83 | //deleteContainer(containerId, builderDockerClient);
84 |
85 | platformDao.updateContainerLastCommit(getCurrentDate(), uid);
86 | String mpilib = platformDao.selectContainerMpilib(uid, containerName);
87 | platformDao.insertImage(fullImageName, uid, getCurrentDate(), metadata, baseimage, mpilib);
88 | }
89 |
90 | builderDockerClient.close();
91 | return containerCommitResponse;
92 | }
93 |
94 | public ContainerCommitResponse distributeImage(String imageName, String uid){
95 | platformDao.updateImageStatus(imageName, uid, "distributing");
96 | ContainerCommitResponse containerCommitResponse = new ContainerCommitResponse();
97 | DockerClient builderDockerClient = new DefaultDockerClient(etcdConnector.getBuilderAddr());
98 | String fullImageName = etcdConnector.getRegistryAddr() + imageName;
99 | try {
100 | platformDao.updateImageStatus(imageName, uid, "distributing");
101 | pushImage(fullImageName, builderDockerClient);
102 | distributeImageToServer(fullImageName);
103 | }catch (Exception e){
104 | e.printStackTrace();
105 | containerCommitResponse.setResponseCode(-1);
106 | platformDao.updateImageStatus(imageName, uid, "error");
107 | }
108 |
109 | platformDao.updateImageStatus(imageName, uid, "ready");
110 | containerCommitResponse.setImageName(fullImageName);
111 | containerCommitResponse.setUserUid(uid);
112 | return containerCommitResponse;
113 | }
114 |
115 | public JSONObject getMetrics(String uid){
116 | JSONObject data = new JSONObject();
117 | List list = platformDao.selectRunningJob(uid);
118 |
119 | // total_usage[0] : CPU, total_usage[1] : Memory
120 | float[] total_usage = new float[2];
121 |
122 | // 2개 이상이 될 일이 없음. 일단은 1개만 돌아간다고 가정.
123 | for(JobMessage jobMessage : list){
124 | if(jobMessage.getStatus().equals("running")){
125 | List conList = platformDao.selectJobContainer(uid, jobMessage.getCreated());
126 |
127 | for(JobContainer jobContainer : conList) {
128 | String url = String.format("https://%s:2375", jobContainer.getServer());
129 | try {
130 | DockerClient dc = DefaultDockerClient.builder()
131 | .uri(url)
132 | .dockerCertificates(new DockerCertificates(Paths.get("keys")))
133 | .build();
134 | float[] container_usage = getContainerUsage(dc, jobContainer.getName());
135 | total_usage[0] = total_usage[0] + container_usage[0];
136 | total_usage[1] = total_usage[1] + container_usage[1];
137 |
138 | } catch (Exception e) {
139 | e.printStackTrace();
140 | }
141 | }
142 | }
143 |
144 | data.put("cpu_usage_sum", total_usage[0]);
145 | data.put("mem_usage_sum", total_usage[1]);
146 | data.put("blki", jobMessage.getBlki());
147 | data.put("blko", jobMessage.getBlko());
148 | data.put("neti", jobMessage.getNeti());
149 | data.put("neto", jobMessage.getNeto());
150 | data.put("mem_limit", jobMessage.getMem() * jobMessage.getCount());
151 | data.put("cpu_limit", jobMessage.getCpu() * jobMessage.getCount());
152 | data.put("count", jobMessage.getCount());
153 | data.put("image", jobMessage.getImage());
154 | }
155 |
156 | return data;
157 | }
158 |
159 | /*
160 | * Create Container
161 | * */
162 |
163 | private float[] getContainerUsage(DockerClient dc, String id) throws Exception{
164 | String usage = ExecuteCmd("ps -e -o pcpu,pmem", id, dc);
165 | String[] process_per_usage = usage.split("\n");
166 | float[] total_usage = new float[2];
167 |
168 | for(int i = 1; i < process_per_usage.length; i++){
169 |
170 | String[] process_per_usage_splited = process_per_usage[i].split(" ");
171 | boolean temp = false;
172 |
173 | for(int j = 0; j < process_per_usage_splited.length; j++){
174 | try{
175 | float temp2 = Float.parseFloat(process_per_usage_splited[j]);
176 | if(!temp){
177 | total_usage[0] += temp2;
178 | temp = true;
179 | }
180 |
181 | else{
182 | total_usage[1] += temp2;
183 | }
184 | }
185 | catch(NumberFormatException e){
186 | continue;
187 | }
188 | }
189 | }
190 |
191 | return total_usage;
192 | }
193 |
194 | private String getPrivateKey(String containerId, DockerClient dc){
195 | return ExecuteCmd("cat /root/.ssh/id_rsa", containerId, dc);
196 | }
197 |
198 | private String ExecuteCmd(String command, String containerId, DockerClient dc) {
199 | String[] arr = command.split(" ");
200 |
201 | try {
202 | ExecCreation execCreation = dc.execCreate(containerId, arr, DockerClient.ExecCreateParam.attachStdout(),
203 | DockerClient.ExecCreateParam.attachStderr());
204 |
205 | String execId = execCreation.id();
206 | LogStream stream = dc.execStart(execId);
207 | final String output = stream.readFully();
208 | stream.close();
209 |
210 | return output;
211 | }
212 | catch(Exception e){
213 | return null;
214 | }
215 | }
216 |
217 | /*
218 | * Commit Container
219 | * */
220 | private String commitContainer(String containerId, String imageName, String tag,
221 | String uid, DockerClient dc) {
222 | String newImageName = etcdConnector.getRegistryAddr() + imageName;
223 |
224 | try {
225 | ContainerConfig config = dc.inspectContainer(containerId).config();
226 |
227 | dc.commitContainer(
228 | containerId, newImageName, tag, config, getCurrentDate(), uid);
229 | }
230 | catch(Exception e){
231 | e.printStackTrace();
232 | return null;
233 | }
234 |
235 | return imageName + ":" + tag;
236 | }
237 |
238 | private void deleteContainer(String containerId, DockerClient dc){
239 | try {
240 | dc.removeContainer(containerId, DockerClient.RemoveContainerParam.forceKill());
241 | }
242 | catch(Exception e){
243 | e.printStackTrace();
244 | }
245 | }
246 |
247 | /*
248 | * Distribute Image
249 | * */
250 | private void pushImage(String imageName, DockerClient dc) throws Exception{
251 | dc.push(imageName, new ProgressHandler(){
252 | @Override
253 | public void progress(ProgressMessage message) throws DockerException {
254 | //System.out.println(message.toString());
255 | }
256 | });
257 | }
258 |
259 | private void distributeImageToServer(String imageName) throws Exception{
260 | List list = etcdConnector.getWorkerAddr();
261 |
262 | for(String str : list){
263 | DockerClient worker = DefaultDockerClient.builder()
264 | .uri(str)
265 | .dockerCertificates(new DockerCertificates(Paths.get("keys")))
266 | .build();
267 | worker.pull(imageName);
268 | worker.close();
269 | }
270 | }
271 |
272 | /*
273 | * etc
274 | * */
275 | private String getCurrentDate(){
276 | long time = System.currentTimeMillis();
277 | SimpleDateFormat dayTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
278 | String str = dayTime.format(new Date(time));
279 |
280 | return str;
281 | }
282 | }
283 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/KistiApplication.java:
--------------------------------------------------------------------------------
1 | package com.icnslab;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class KistiApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(KistiApplication.class, args);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/assist/JSONAssistant.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.assist;
2 |
3 | import jdk.nashorn.internal.parser.JSONParser;
4 | import org.json.simple.JSONObject;
5 | import org.json.simple.JSONValue;
6 |
7 | /**
8 | * Created by alicek106 on 2017-08-04.
9 | */
10 | public class JSONAssistant {
11 | public static String getString(JSONObject job, String arg){
12 | return (String)job.get(arg);
13 | }
14 |
15 | public static JSONObject parseJSON(String str){
16 | try {
17 | Object obj = JSONValue.parseWithException(str);
18 | JSONObject jobj = (JSONObject) obj;
19 | return jobj;
20 | } catch (Exception e) {
21 | e.printStackTrace();
22 | }
23 | return null;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/assist/WebConfig.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.assist;
2 |
3 | import org.springframework.context.annotation.Configuration;
4 | import org.springframework.web.servlet.config.annotation.CorsRegistry;
5 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
7 |
8 | @Configuration
9 | @EnableWebMvc
10 | public class WebConfig extends WebMvcConfigurerAdapter
11 | {
12 | @Override
13 | public void addCorsMappings(CorsRegistry registry)
14 | {
15 | registry.addMapping("/**");
16 | }
17 | }
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/database/PlatformDao.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.database;
2 |
3 | import com.icnslab.message.Container;
4 | import com.icnslab.message.Image;
5 | import com.icnslab.message.JobContainer;
6 | import com.icnslab.message.JobMessage;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.jdbc.core.BeanPropertyRowMapper;
9 | import org.springframework.jdbc.core.JdbcTemplate;
10 | import org.springframework.stereotype.Repository;
11 |
12 | import java.util.List;
13 |
14 | /**
15 | * Created by alicek106 on 2017-08-03.
16 | */
17 | @Repository
18 | public class PlatformDao {
19 | @Autowired
20 | private JdbcTemplate jdbcTemplate;
21 |
22 | public void insertContainer(Container container){
23 | String query = String.format("insert into build_container values('%s','%s','%s','%s','%s','%s','%s','%s');",
24 | container.getName(), container.getUser(), container.getServer(), "true", "none", container.getCreated(),
25 | container.getBaseimage(), container.getMpilib());
26 | jdbcTemplate.update(query);
27 | }
28 |
29 | public String selectContainerId(String user){
30 | String query = String.format("SELECT name FROM build_container where user = '%s' and alive = 'true'", user);
31 | return jdbcTemplate.queryForObject(query, String.class);
32 | }
33 |
34 | public List selectContainer(String user){
35 | String query = String.format("SELECT * FROM build_container where user = '%s'", user);
36 | List container = jdbcTemplate.query(query, new BeanPropertyRowMapper(Container.class));
37 | return container;
38 | }
39 |
40 | public String selectContainerMpilib(String user, String container){
41 | String query = String.format("SELECT mpilib FROM build_container where user = '%s' and name = '%s'", user, container);
42 | String mpilib = jdbcTemplate.queryForObject(query, String.class);
43 | return mpilib;
44 | }
45 |
46 | public void updateContainerLastCommit(String date, String user){
47 | String query = String.format("update build_container set lastcommit='%s' where user = '%s' and alive = 'true'", date, user);
48 | jdbcTemplate.update(query);
49 | }
50 |
51 | public void deleteContainer(String container, String user){
52 | String query = String.format("delete from build_container where user = '%s' and name = '%s'", user, container);
53 | jdbcTemplate.update(query);
54 | }
55 |
56 | public void insertImage(String name, String user, String created, String metadata, String baseimage, String mpilib){
57 | String query = String.format("insert into image values('%s','%s','%s','%s','%s', '%s', '%s');",
58 | name, user, created, "not ready", metadata, baseimage, mpilib);
59 | jdbcTemplate.update(query);
60 | }
61 |
62 | public void updateImageStatus(String name, String user, String status){
63 | String query = String.format("update image set status='%s' where name = '%s' and user = '%s'", status, name, user);
64 | jdbcTemplate.update(query);
65 | }
66 |
67 | public List selectImage(String user) {
68 | String query = String.format("SELECT * FROM image where user = '%s'", user);
69 | List image = jdbcTemplate.query(query, new BeanPropertyRowMapper(Image.class));
70 | return image;
71 | }
72 |
73 | public List selectJobContainer(String user){
74 | String query = String.format("SELECT * FROM job_container where user = '%s'", user);
75 | List jobContainers = jdbcTemplate.query(query, new BeanPropertyRowMapper(JobContainer.class));
76 | return jobContainers;
77 | }
78 |
79 | public List selectRunningJob(String uid){
80 | String query = String.format("SELECT * FROM job where user = '%s' and status = 'running'", uid);
81 | List jobs = jdbcTemplate.query(query, new BeanPropertyRowMapper(JobMessage.class));
82 | return jobs;
83 | }
84 |
85 | public List selectJobContainer(String uid, String created){
86 | String query = String.format("SELECT * FROM job_container where user = '%s' and created = '%s'", uid, created);
87 | List jobs = jdbcTemplate.query(query, new BeanPropertyRowMapper(JobContainer.class));
88 | return jobs;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/message/Container.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.message;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by alicek106 on 2017-08-03.
7 | */
8 | public class Container implements Serializable{
9 | private String name;
10 | private String user;
11 | private String server;
12 | private String alive;
13 | private String lastcommit;
14 | private String created;
15 | private String baseimage;
16 | private String mpilib;
17 |
18 | public Container(){}
19 |
20 | public Container(String name, String user, String server, String alive, String lastcommit, String created, String baseimage, String mpilib) {
21 | this.name = name;
22 | this.user = user;
23 | this.server = server;
24 | this.alive = alive;
25 | this.lastcommit = lastcommit;
26 | this.created = created;
27 | this.baseimage = baseimage;
28 | this.mpilib = mpilib;
29 | }
30 |
31 | public String getName() {
32 | return name;
33 | }
34 |
35 | public void setName(String name) {
36 | this.name = name;
37 | }
38 |
39 | public String getUser() {
40 | return user;
41 | }
42 |
43 | public void setUser(String user) {
44 | this.user = user;
45 | }
46 |
47 | public String getServer() {
48 | return server;
49 | }
50 |
51 | public void setServer(String server) {
52 | this.server = server;
53 | }
54 |
55 | public String getAlive() {
56 | return alive;
57 | }
58 |
59 | public void setAlive(String alive) {
60 | this.alive = alive;
61 | }
62 |
63 | public String getLastcommit() {
64 | return lastcommit;
65 | }
66 |
67 | public void setLastcommit(String lastcommit) {
68 | this.lastcommit = lastcommit;
69 | }
70 |
71 | public String getCreated() {
72 | return created;
73 | }
74 |
75 | public void setCreated(String created) {
76 | this.created = created;
77 | }
78 |
79 | public String getBaseimage() {
80 | return baseimage;
81 | }
82 |
83 | public void setBaseimage(String baseimage) {
84 | this.baseimage = baseimage;
85 | }
86 |
87 | public String getMpilib() {
88 | return mpilib;
89 | }
90 |
91 | public void setMpilib(String mpilib) {
92 | this.mpilib = mpilib;
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/message/ContainerBuilder.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.message;
2 |
3 | public class ContainerBuilder {
4 | private String name;
5 | private String user;
6 | private String server;
7 | private String alive;
8 | private String lastcommit;
9 | private String created;
10 | private String baseImage;
11 | private String mpilib;
12 |
13 | public ContainerBuilder setName(String name) {
14 | this.name = name;
15 | return this;
16 | }
17 |
18 | public ContainerBuilder setUser(String user) {
19 | this.user = user;
20 | return this;
21 | }
22 |
23 | public ContainerBuilder setServer(String server) {
24 | this.server = server;
25 | return this;
26 | }
27 |
28 | public ContainerBuilder setAlive(String alive) {
29 | this.alive = alive;
30 | return this;
31 | }
32 |
33 | public ContainerBuilder setLastcommit(String lastcommit) {
34 | this.lastcommit = lastcommit;
35 | return this;
36 | }
37 |
38 | public ContainerBuilder setCreated(String created) {
39 | this.created = created;
40 | return this;
41 | }
42 |
43 | public ContainerBuilder setBaseImage(String baseImage) {
44 | this.baseImage = baseImage;
45 | return this;
46 | }
47 |
48 | public ContainerBuilder setMpilib(String mpilib) {
49 | this.mpilib = mpilib;
50 | return this;
51 | }
52 |
53 | public Container createContainer() {
54 | return new Container(name, user, server, alive, lastcommit, created, baseImage, mpilib);
55 | }
56 | }
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/message/ContainerCommitResponse.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.message;
2 |
3 | /**
4 | * Created by alicek106 on 2017-08-03.
5 | */
6 | public class ContainerCommitResponse {
7 | private int responseCode;
8 | private String userUid;
9 | private String imageName;
10 |
11 | public int getResponseCode() {
12 | return responseCode;
13 | }
14 |
15 | public void setResponseCode(int responseCode) {
16 | this.responseCode = responseCode;
17 | }
18 |
19 | public String getUserUid() {
20 | return userUid;
21 | }
22 |
23 | public void setUserUid(String userUid) {
24 | this.userUid = userUid;
25 | }
26 |
27 | public String getImageName() {
28 | return imageName;
29 | }
30 |
31 | public void setImageName(String imageName) {
32 | this.imageName = imageName;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/message/ContainerCreationResponse.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.message;
2 |
3 | /**
4 | * Created by alicek106 on 2017-08-03.
5 | */
6 | public class ContainerCreationResponse {
7 | private String accessUrl;
8 | private int responseCode;
9 | private String secretAccessKey;
10 | private String userUid;
11 |
12 | public String getAccessUrl() {
13 | return accessUrl;
14 | }
15 |
16 | public void setAccessUrl(String accessUrl) {
17 | this.accessUrl = accessUrl;
18 | }
19 |
20 | public int getResponseCode() {
21 | return responseCode;
22 | }
23 |
24 | public void setResponseCode(int responseCode) {
25 | this.responseCode = responseCode;
26 | }
27 |
28 | public String getSecretAccessKey() {
29 | return secretAccessKey;
30 | }
31 |
32 | public void setSecretAccessKey(String secretAccessKey) {
33 | this.secretAccessKey = secretAccessKey;
34 | }
35 |
36 | public String getUserUid() {
37 | return userUid;
38 | }
39 |
40 | public void setUserUid(String userUid) {
41 | this.userUid = userUid;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/message/ContainerDeleteResponse.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.message;
2 |
3 | /**
4 | * Created by alicek106 on 2017-08-03.
5 | */
6 | public class ContainerDeleteResponse {
7 | private int responseCode;
8 | private String userUid;
9 |
10 | public int getResponseCode() {
11 | return responseCode;
12 | }
13 |
14 | public void setResponseCode(int responseCode) {
15 | this.responseCode = responseCode;
16 | }
17 |
18 | public String getUserUid() {
19 | return userUid;
20 | }
21 |
22 | public void setUserUid(String userUid) {
23 | this.userUid = userUid;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/message/Image.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.message;
2 |
3 | import java.io.Serializable;
4 |
5 | /**
6 | * Created by alicek106 on 2017-08-03.
7 | */
8 | public class Image implements Serializable{
9 | private String name;
10 | private String user;
11 | private String created;
12 | private String status;
13 | private String metadata;
14 | private String baseimage;
15 | private String mpilib;
16 |
17 | public String getMpilib() { return mpilib; }
18 |
19 | public void setMpilib(String mpilib) { this.mpilib = mpilib; }
20 |
21 | public String getBaseimage() { return baseimage; }
22 |
23 | public void setBaseimage(String baseimage) { this.baseimage = baseimage; }
24 |
25 | public String getName() {
26 | return name;
27 | }
28 |
29 | public void setName(String name) {
30 | this.name = name;
31 | }
32 |
33 | public String getUser() {
34 | return user;
35 | }
36 |
37 | public void setUser(String user) {
38 | this.user = user;
39 | }
40 |
41 | public String getCreated() {
42 | return created;
43 | }
44 |
45 | public void setCreated(String created) {
46 | this.created = created;
47 | }
48 |
49 | public String getStatus() {
50 | return status;
51 | }
52 |
53 | public void setStatus(String status) {
54 | this.status = status;
55 | }
56 |
57 | public String getMetadata() {
58 | return metadata;
59 | }
60 |
61 | public void setMetadata(String metadata) {
62 | this.metadata = metadata;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/message/JobContainer.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.message;
2 |
3 | public class JobContainer {
4 | private String name;
5 | private String user;
6 | private String server;
7 | private String alive;
8 | private String created;
9 | private String jobName;
10 | private String image;
11 |
12 | public String getImage() {
13 | return image;
14 | }
15 |
16 | public void setImage(String image) {
17 | this.image = image;
18 | }
19 | public String getJobName() {
20 | return jobName;
21 | }
22 |
23 | public void setJobName(String jobName) {
24 | this.jobName = jobName;
25 | }
26 | public String getName() {
27 | return name;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 |
34 | public String getUser() {
35 | return user;
36 | }
37 |
38 | public void setUser(String user) {
39 | this.user = user;
40 | }
41 |
42 | public String getServer() {
43 | return server;
44 | }
45 |
46 | public void setServer(String server) {
47 | this.server = server;
48 | }
49 |
50 | public String getAlive() {
51 | return alive;
52 | }
53 |
54 | public void setAlive(String alive) {
55 | this.alive = alive;
56 | }
57 |
58 | public String getCreated() {
59 | return created;
60 | }
61 |
62 | public void setCreated(String created) {
63 | this.created = created;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/message/JobMessage.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.message;
2 |
3 | /**
4 | * Created by alicek106 on 2017-08-04.
5 | */
6 | public class JobMessage {
7 | String name;
8 | String user;
9 | String image;
10 | int count;
11 | int cpu;
12 | int mem;
13 | int blko;
14 | int blki;
15 |
16 | public int getBlko() {
17 | return blko;
18 | }
19 |
20 | public void setBlko(int blko) {
21 | this.blko = blko;
22 | }
23 |
24 | public int getBlki() {
25 | return blki;
26 | }
27 |
28 | public void setBlki(int blki) {
29 | this.blki = blki;
30 | }
31 |
32 | public int getNeto() {
33 | return neto;
34 | }
35 |
36 | public void setNeto(int neto) {
37 | this.neto = neto;
38 | }
39 |
40 | public int getNeti() {
41 | return neti;
42 | }
43 |
44 | public void setNeti(int neti) {
45 | this.neti = neti;
46 | }
47 |
48 | int neto;
49 | int neti;
50 | //String exepath;
51 | String mpicmd;
52 | String status;
53 | String created;
54 | String metadata;
55 |
56 | public JobMessage(){}
57 |
58 | public JobMessage(String name, String user, String image, int count, int cpu, int mem,
59 | int blki, int blko, int neti, int neto, String mpicmd, String status,
60 | String created, String metadata) {
61 | this.name = name;
62 | this.user = user;
63 | this.image = image;
64 | this.count = count;
65 | this.cpu = cpu;
66 | this.mem = mem;
67 | this.blki = blki;
68 | this.blko = blko;
69 | this.neti = neti;
70 | this.neto = neto;
71 | // this.exepath = exepath;
72 | this.mpicmd = mpicmd;
73 | this.status = status;
74 | this.created = created;
75 | this.metadata = metadata;
76 | }
77 |
78 | public String getName() {
79 | return name;
80 | }
81 |
82 | public void setName(String name) {
83 | this.name = name;
84 | }
85 |
86 | public String getUser() {
87 | return user;
88 | }
89 |
90 | public void setUser(String user) {
91 | this.user = user;
92 | }
93 |
94 | public String getImage() {
95 | return image;
96 | }
97 |
98 | public void setImage(String image) {
99 | this.image = image;
100 | }
101 |
102 | public int getCount() {
103 | return count;
104 | }
105 |
106 | public void setCount(int count) {
107 | this.count = count;
108 | }
109 |
110 | public int getCpu() {
111 | return cpu;
112 | }
113 |
114 | public void setCpu(int cpu) {
115 | this.cpu = cpu;
116 | }
117 |
118 | public int getMem() {
119 | return mem;
120 | }
121 |
122 | public void setMem(int mem) {
123 | this.mem = mem;
124 | }
125 |
126 | // public String getExepath() {
127 | // return exepath;
128 | // }
129 | //
130 | // public void setExepath(String exepath) {
131 | // this.exepath = exepath;
132 | // }
133 |
134 | public String getMpicmd() {
135 | return mpicmd;
136 | }
137 |
138 | public void setMpicmd(String mpicmd) {
139 | this.mpicmd = mpicmd;
140 | }
141 |
142 | public String getStatus() {
143 | return status;
144 | }
145 |
146 | public void setStatus(String status) {
147 | this.status = status;
148 | }
149 |
150 | public String getCreated() {
151 | return created;
152 | }
153 |
154 | public void setCreated(String created) {
155 | this.created = created;
156 | }
157 |
158 | public String getMetadata() {
159 | return metadata;
160 | }
161 |
162 | public void setMetadata(String metadata) {
163 | this.metadata = metadata;
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/message/User.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.message;
2 |
3 | /**
4 | * Created by alicek106 on 2017-07-17.
5 | */
6 | public class User {
7 | private String id;
8 | private String password;
9 |
10 | public String getId() {
11 | return id;
12 | }
13 |
14 | public void setId(String id) {
15 | this.id = id;
16 | }
17 |
18 | public String getPassword() {
19 | return password;
20 | }
21 |
22 | public void setPassword(String password) {
23 | this.password = password;
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/mpiSetter/MpiSetter.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.mpiSetter;
2 |
3 | import com.icnslab.message.Container;
4 | import com.spotify.docker.client.DockerClient;
5 | import com.spotify.docker.client.messages.ContainerInfo;
6 |
7 | import java.util.List;
8 |
9 | /**
10 | * Created by alicek106 on 2017-08-06.
11 | */
12 | public interface MpiSetter {
13 | public static final String MPI_LIB_BIND_PATH = null;
14 | public static final String MPI_EXAMPLE_BIND_PATH = null;
15 | public static final String MPI_EXE_BIND_PATH = "/mnt/lustre/scratch/%s/exe:/root/exe";
16 | public static final String MPI_OUTPUT_PATH = "/mnt/lustre/scratch/%s/output:/root/output";
17 |
18 | public abstract List setMpiBind(Container jobMessage);
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/java/com/icnslab/mpiSetter/MpichSetter.java:
--------------------------------------------------------------------------------
1 | package com.icnslab.mpiSetter;
2 |
3 | import com.icnslab.message.Container;
4 | import com.spotify.docker.client.DockerClient;
5 | import com.spotify.docker.client.messages.ContainerInfo;
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Created by alicek106 on 2017-08-06.
11 | */
12 | public class MpichSetter implements MpiSetter {
13 | public static final String MPI_LIB_BIND_PATH = "/mnt/lustre/app/mpich/%s/lib/:/home/app/mpich/mpich-libs";
14 | public static final String MPI_EXAMPLE_BIND_PATH = "/mnt/lustre/app/mpich/examples/:/home/app/mpich/example";
15 |
16 | public List setMpiBind(Container jobMessage){
17 | // MPI Library Specific ... Settings
18 | List binds = new ArrayList();
19 | binds.add(String.format(MPI_LIB_BIND_PATH, jobMessage.getMpilib().replace("mpich", "")));
20 | binds.add(MPI_EXAMPLE_BIND_PATH);
21 |
22 | // default
23 | binds.add(String.format(MPI_EXE_BIND_PATH, jobMessage.getUser()));
24 | return binds;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=SpringBootJdbc
2 | spring.datasource.url=jdbc:mysql://192.168.0.10/hpc
3 | spring.datasource.username=root
4 | spring.datasource.password=1q2w3e4r
5 | spring.datasource.driverClassName=com.mysql.jdbc.Driver
6 |
7 | spring.thymeleaf.cache=false
8 | spring.devtools.livereload.enabled=true
--------------------------------------------------------------------------------
/src/test/java/com/icnslab/KistiApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.icnslab;
2 |
3 | import org.junit.Test;
4 | import org.junit.runner.RunWith;
5 | import org.springframework.boot.test.context.SpringBootTest;
6 | import org.springframework.test.context.junit4.SpringRunner;
7 |
8 | @RunWith(SpringRunner.class)
9 | @SpringBootTest
10 | public class KistiApplicationTests {
11 |
12 | @Test
13 | public void contextLoads() {
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------