Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
coastal-tep
interactive-application-service
Commits
82044df5
Commit
82044df5
authored
7 years ago
by
Christoph Holter
Browse files
Options
Download
Plain Diff
Merge branch 'master' of
https://gitlab.acri-cwa.fr/coastal-tep/interactive-application-service
parents
1d1fec96
9adf0974
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
108 additions
and
44 deletions
+108
-44
backend/src/main/java/cc/catalysts/api/InteractiveApplicationServiceApiController.java
...lysts/api/InteractiveApplicationServiceApiController.java
+62
-20
backend/src/main/java/cc/catalysts/exception/DockerException.java
...src/main/java/cc/catalysts/exception/DockerException.java
+9
-0
backend/src/main/java/cc/catalysts/service/DockerService.java
...end/src/main/java/cc/catalysts/service/DockerService.java
+0
-1
backend/src/main/java/cc/catalysts/service/UamService.java
backend/src/main/java/cc/catalysts/service/UamService.java
+9
-4
backend/src/main/java/cc/catalysts/uam/model/ResourceType.java
...nd/src/main/java/cc/catalysts/uam/model/ResourceType.java
+0
-2
backend/src/main/resources/log4j.properties
backend/src/main/resources/log4j.properties
+8
-0
frontend/src/main/web/app/container.component.ts
frontend/src/main/web/app/container.component.ts
+2
-6
frontend/src/main/web/app/image-item.component.html
frontend/src/main/web/app/image-item.component.html
+3
-2
frontend/src/main/web/app/image-item.component.ts
frontend/src/main/web/app/image-item.component.ts
+15
-9
No files found.
backend/src/main/java/cc/catalysts/api/InteractiveApplicationServiceApiController.java
View file @
82044df5
package
cc.catalysts.api
;
import
cc.catalysts.config.NavbarConfig
;
import
cc.catalysts.exception.DockerException
;
import
cc.catalysts.exception.UamResourceException
;
import
cc.catalysts.repository.DockerContainerRepository
;
import
cc.catalysts.service.DockerService
;
import
cc.catalysts.service.UamService
;
import
io.swagger.annotations.ApiParam
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -22,6 +25,8 @@ public class InteractiveApplicationServiceApiController implements InteractiveAp
private
final
UamService
uamService
;
private
final
NavbarConfig
navbarConfig
;
private
final
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
InteractiveApplicationServiceApiController
.
class
);
@Autowired
public
InteractiveApplicationServiceApiController
(
DockerService
dockerService
,
DockerContainerRepository
repository
,
...
...
@@ -38,23 +43,28 @@ public class InteractiveApplicationServiceApiController implements InteractiveAp
}
@Override
public
DockerContainer
startContainer
(
@RequestBody
StartContainerParameters
parameters
,
Principal
principal
)
throws
UamResource
Exception
{
public
DockerContainer
startContainer
(
@RequestBody
StartContainerParameters
parameters
,
Principal
principal
)
throws
Api
Exception
{
if
(
this
.
uamService
.
getAvailableContainers
(
userFromPrincipal
(
principal
))
<=
0
)
{
throw
new
UamResourceException
(
"No
container
s available"
);
throw
new
UamResourceException
(
"No
more app
s available"
);
}
if
(!
this
.
uamService
.
consumeContainer
(
userFromPrincipal
(
principal
)))
{
if
(!
this
.
uamService
.
consumeContainer
(
userFromPrincipal
(
principal
)
,
parameters
.
getImage
().
getName
()
))
{
throw
new
UamResourceException
(
"Could not consume resource"
);
}
DockerContainer
ctn
=
dockerService
.
startContainer
(
parameters
.
getImage
(),
userFromPrincipal
(
principal
),
parameters
.
getName
(),
parameters
.
getDescription
());
if
(
parameters
.
isShared
())
{
dockerService
.
shareContainer
(
ctn
,
userFromPrincipal
(
principal
));
try
{
DockerContainer
ctn
=
dockerService
.
startContainer
(
parameters
.
getImage
(),
userFromPrincipal
(
principal
),
parameters
.
getName
(),
parameters
.
getDescription
());
if
(
parameters
.
isShared
())
{
dockerService
.
shareContainer
(
ctn
,
userFromPrincipal
(
principal
));
}
return
ctn
;
}
catch
(
com
.
github
.
dockerjava
.
api
.
exception
.
DockerException
e
)
{
LOGGER
.
error
(
"app start failed, exception was: "
+
e
.
getMessage
());
throw
new
DockerException
(
"Start of app failed"
);
}
return
ctn
;
}
@Override
...
...
@@ -62,30 +72,62 @@ public class InteractiveApplicationServiceApiController implements InteractiveAp
return
dockerContainerRepository
.
getRunningContainers
(
userFromPrincipal
(
principal
));
}
@Override
public
void
stopContainer
(
@RequestBody
DockerContainer
ctn
,
Principal
principal
)
{
dockerService
.
stopContainer
(
ctn
,
userFromPrincipal
(
principal
));
Principal
principal
)
throws
ApiException
{
try
{
dockerService
.
stopContainer
(
ctn
,
userFromPrincipal
(
principal
));
}
catch
(
com
.
github
.
dockerjava
.
api
.
exception
.
DockerException
e
)
{
LOGGER
.
error
(
"app stop failed, exception was: "
+
e
.
getMessage
());
throw
new
DockerException
(
"Stop of app failed"
);
}
}
@Override
public
void
resumeContainer
(
@RequestBody
DockerContainer
ctn
,
Principal
principal
)
{
dockerService
.
resumeContainer
(
ctn
,
userFromPrincipal
(
principal
));
public
void
resumeContainer
(
@RequestBody
DockerContainer
ctn
,
Principal
principal
)
throws
ApiException
{
try
{
dockerService
.
resumeContainer
(
ctn
,
userFromPrincipal
(
principal
));
}
catch
(
com
.
github
.
dockerjava
.
api
.
exception
.
DockerException
e
)
{
LOGGER
.
error
(
"app resume failed, exception was: "
+
e
.
getMessage
());
throw
new
DockerException
(
"Resume of app failed"
);
}
}
@Override
public
void
removeContainer
(
@RequestBody
DockerContainer
ctn
,
Principal
principal
)
{
this
.
dockerService
.
removeContainer
(
ctn
,
userFromPrincipal
(
principal
));
this
.
uamService
.
allocateContainer
(
userFromPrincipal
(
principal
));
public
void
removeContainer
(
@RequestBody
DockerContainer
ctn
,
Principal
principal
)
throws
ApiException
{
try
{
this
.
dockerService
.
removeContainer
(
ctn
,
userFromPrincipal
(
principal
));
}
catch
(
com
.
github
.
dockerjava
.
api
.
exception
.
DockerException
e
)
{
LOGGER
.
error
(
"app removal failed, exception was: "
+
e
.
getMessage
());
throw
new
DockerException
(
"Removal of app failed"
);
}
if
(!
this
.
uamService
.
allocateContainer
(
userFromPrincipal
(
principal
),
ctn
.
getImageName
()))
{
throw
new
UamResourceException
(
"Could not allocate resource"
);
};
}
@Override
public
void
shareContainer
(
@ApiParam
(
value
=
"The container to share"
)
@RequestBody
DockerContainer
ctn
,
Principal
principal
)
{
this
.
dockerService
.
shareContainer
(
ctn
,
userFromPrincipal
(
principal
));
public
void
shareContainer
(
@ApiParam
(
value
=
"The app to share"
)
@RequestBody
DockerContainer
ctn
,
Principal
principal
)
throws
ApiException
{
try
{
this
.
dockerService
.
shareContainer
(
ctn
,
userFromPrincipal
(
principal
));
}
catch
(
com
.
github
.
dockerjava
.
api
.
exception
.
DockerException
e
)
{
LOGGER
.
error
(
"sharing failed, exception was: "
+
e
.
getMessage
());
throw
new
DockerException
(
"Sharing of app failed"
);
}
}
@Override
public
void
unshareContainer
(
@ApiParam
(
value
=
"The container to unshare"
)
@RequestBody
DockerContainer
ctn
,
Principal
principal
)
{
public
void
unshareContainer
(
@ApiParam
(
value
=
"The app to unshare"
)
@RequestBody
DockerContainer
ctn
,
Principal
principal
)
throws
ApiException
{
try
{
this
.
dockerService
.
unshareContainer
(
ctn
,
userFromPrincipal
(
principal
));
}
catch
(
com
.
github
.
dockerjava
.
api
.
exception
.
DockerException
e
)
{
LOGGER
.
error
(
"unsharing failed, exception was: "
+
e
.
getMessage
());
throw
new
DockerException
(
"Unsharing of app failed"
);
}
}
@Override
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/cc/catalysts/exception/DockerException.java
0 → 100644
View file @
82044df5
package
cc.catalysts.exception
;
import
cc.catalysts.api.ApiException
;
public
class
DockerException
extends
ApiException
{
public
DockerException
(
String
message
)
{
super
(
"Docker exception: "
,
message
);
}
}
This diff is collapsed.
Click to expand it.
backend/src/main/java/cc/catalysts/service/DockerService.java
View file @
82044df5
...
...
@@ -21,7 +21,6 @@ import org.apache.commons.lang.text.StrSubstitutor;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
java.text.MessageFormat
;
import
java.text.Normalizer
;
import
java.util.*
;
import
java.util.stream.Collectors
;
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/java/cc/catalysts/service/UamService.java
View file @
82044df5
...
...
@@ -74,8 +74,8 @@ public class UamService {
return
(
int
)
response
.
getBody
().
getCount
();
}
public
boolean
consumeContainer
(
User
user
)
{
ConsumptionDto
consumptionDto
=
new
ConsumptionDto
(
this
.
resourceConcurrentContainers
,
1
,
"started
Container"
);
public
boolean
consumeContainer
(
User
user
,
String
appName
)
{
ConsumptionDto
consumptionDto
=
new
ConsumptionDto
(
this
.
resourceConcurrentContainers
,
1
,
"started
app: "
+
appName
);
RestTemplate
restTemplate
=
new
RestTemplate
();
restTemplate
.
getMessageConverters
().
add
(
new
MappingJackson2HttpMessageConverter
());
ResponseEntity
<
ConsumptionResponseDto
>
response
=
restTemplate
.
exchange
(
...
...
@@ -92,8 +92,8 @@ public class UamService {
return
true
;
}
public
void
allocateContainer
(
User
user
)
{
AllocationDto
allocationDto
=
new
AllocationDto
(
this
.
resourceConcurrentContainers
,
1
,
"removed
Container"
,
null
);
public
boolean
allocateContainer
(
User
user
,
String
appName
)
{
AllocationDto
allocationDto
=
new
AllocationDto
(
this
.
resourceConcurrentContainers
,
1
,
"removed
app: "
+
appName
,
null
);
RestTemplate
restTemplate
=
new
RestTemplate
();
restTemplate
.
getMessageConverters
().
add
(
new
MappingJackson2HttpMessageConverter
());
ResponseEntity
<
String
>
response
=
new
RestTemplate
().
exchange
(
...
...
@@ -103,5 +103,10 @@ public class UamService {
String
.
class
,
user
.
getId
()
);
if
(
response
==
null
||
!
response
.
getStatusCode
().
equals
(
HttpStatus
.
OK
))
{
return
false
;
}
return
true
;
}
}
This diff is collapsed.
Click to expand it.
backend/src/main/java/cc/catalysts/uam/model/ResourceType.java
View file @
82044df5
...
...
@@ -2,8 +2,6 @@ package cc.catalysts.uam.model;
import
com.fasterxml.jackson.annotation.JsonIgnoreProperties
;
import
javax.validation.constraints.Size
;
@JsonIgnoreProperties
(
ignoreUnknown
=
true
)
public
class
ResourceType
{
...
...
This diff is collapsed.
Click to expand it.
backend/src/main/resources/log4j.properties
0 → 100644
View file @
82044df5
# Root logger option
log4j.rootLogger
=
INFO, stdout
# Direct log messages to stdout
log4j.appender.stdout
=
org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target
=
System.out
log4j.appender.stdout.layout
=
org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern
=
%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
This diff is collapsed.
Click to expand it.
frontend/src/main/web/app/container.component.ts
View file @
82044df5
...
...
@@ -27,19 +27,15 @@ export class ContainerComponent {
public
constructor
(
private
apiService
:
InteractiveApplicationServiceApi
)
{
}
public
getStateName
():
string
{
return
DockerContainer
.
StateEnum
[
this
.
container
.
state
];
}
public
isPausedContainer
():
boolean
{
return
this
.
container
.
state
===
DockerContainer
.
StateEnum
.
STOPPED
;
}
public
getShareToggleButtonInfo
():
string
{
if
(
this
.
container
.
shared
)
{
return
'
Make private
'
;
return
'
Make
app
private
'
;
}
else
{
return
'
Share
container
'
;
return
'
Share
app
'
;
}
}
...
...
This diff is collapsed.
Click to expand it.
frontend/src/main/web/app/image-item.component.html
View file @
82044df5
...
...
@@ -14,7 +14,7 @@
<template
#startContainerModal
let-start=
"close"
let-d=
"dismiss"
>
<div
class=
"modal-header"
>
<h5
class=
"modal-title"
id=
"startContainerModalLabel"
>
Start
container
{{ imageInfo.image.name }}
</h5>
<h5
class=
"modal-title"
id=
"startContainerModalLabel"
>
Start
app
{{ imageInfo.image.name }}
</h5>
<button
type=
"button"
class=
"close"
aria-label=
"Close"
(click)=
"d()"
>
<span
aria-hidden=
"true"
>
×
</span>
</button>
...
...
@@ -56,7 +56,8 @@
<template
#errorMessageModal
let-d=
"dismiss"
>
<div
class=
"modal-header"
>
<h5
class=
"modal-title"
>
Something went wrong
</h5>
<h5
class=
"modal-title"
*ngIf=
"!errorTitle"
>
Something went wrong
</h5>
<h5
class=
"modal-title"
*ngIf=
"errorTitle"
>
{{ errorTitle }}
</h5>
<button
type=
"button"
class=
"close"
aria-label=
"Close"
(click)=
"d()"
>
<span
aria-hidden=
"true"
>
×
</span>
</button>
...
...
This diff is collapsed.
Click to expand it.
frontend/src/main/web/app/image-item.component.ts
View file @
82044df5
...
...
@@ -42,6 +42,7 @@ export class ImageItemComponent {
public
selectedContainer
?:
DockerContainer
=
null
;
public
errorTitle
:
string
;
public
errorMessage
:
string
;
constructor
(
private
dockerService
:
DockerImageService
,
...
...
@@ -78,9 +79,10 @@ export class ImageItemComponent {
},
(
err
)
=>
{
try
{
this
.
showError
((
<
ApiException
>
err
.
json
()).
whatsWrong
);
const
exception
:
ApiException
=
<
ApiException
>
err
.
json
();
this
.
showError
(
exception
.
message
,
exception
.
whatsWrong
);
}
catch
(
_
)
{
this
.
showError
(
'
Could not start
container.
'
);
this
.
showError
(
'
Could not start
app.
'
,
null
);
}
console
.
error
(
err
);
}
...
...
@@ -103,9 +105,10 @@ export class ImageItemComponent {
},
(
err
)
=>
{
try
{
this
.
showError
((
<
ApiException
>
err
.
json
()).
whatsWrong
);
const
exception
:
ApiException
=
<
ApiException
>
err
.
json
();
this
.
showError
(
exception
.
message
,
exception
.
whatsWrong
);
}
catch
(
_
)
{
this
.
showError
(
'
Could not remove
container.
'
);
this
.
showError
(
'
Could not remove
app.
'
,
null
);
}
console
.
error
(
err
);
}
...
...
@@ -119,9 +122,10 @@ export class ImageItemComponent {
()
=>
container
.
state
=
DockerContainer
.
StateEnum
.
RUNNING
,
(
err
)
=>
{
try
{
this
.
showError
((
<
ApiException
>
err
.
json
()).
whatsWrong
);
const
exception
:
ApiException
=
<
ApiException
>
err
.
json
();
this
.
showError
(
exception
.
message
,
exception
.
whatsWrong
);
}
catch
(
_
)
{
this
.
showError
(
'
Could not resume
container.
'
);
this
.
showError
(
'
Could not resume
app.
'
,
null
);
}
console
.
error
(
err
);
}
...
...
@@ -135,9 +139,10 @@ export class ImageItemComponent {
()
=>
container
.
state
=
DockerContainer
.
StateEnum
.
STOPPED
,
(
err
)
=>
{
try
{
this
.
showError
((
<
ApiException
>
err
.
json
()).
whatsWrong
);
const
exception
:
ApiException
=
<
ApiException
>
err
.
json
();
this
.
showError
(
exception
.
message
,
exception
.
whatsWrong
);
}
catch
(
_
)
{
this
.
showError
(
'
Could not stop
container.
'
);
this
.
showError
(
'
Could not stop
app.
'
,
null
);
}
console
.
error
(
err
);
}
...
...
@@ -145,7 +150,8 @@ export class ImageItemComponent {
}
}
private
showError
(
message
:
string
)
{
private
showError
(
message
:
string
,
title
:
string
)
{
this
.
errorTitle
=
title
;
this
.
errorMessage
=
message
;
this
.
modalService
.
open
(
this
.
errorMessageModalRef
);
}
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment