Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
europdx
k8s
cbio-on-demand
API
Commits
decbbc45
Commit
decbbc45
authored
Jul 18, 2019
by
Ľuboslav Pivarč
Browse files
erorr handling in listall fixed && refactor constants
parent
0009c8d5
Changes
3
Hide whitespace changes
Inline
Side-by-side
cbioondemandK8S/src/main/java/cz/muni/ics/edirex/cbioondemandK8S/Utils.java
View file @
decbbc45
package
cz.muni.ics.edirex.cbioondemandK8S
;
import
com.cronutils.builder.CronBuilder
;
import
com.cronutils.mapper.CronMapper
;
import
com.cronutils.model.Cron
;
import
com.cronutils.model.CronType
;
import
com.cronutils.model.definition.CronDefinition
;
import
com.cronutils.model.definition.CronDefinitionBuilder
;
import
com.cronutils.model.time.ExecutionTime
;
import
com.cronutils.parser.CronParser
;
...
...
@@ -13,13 +11,11 @@ import com.google.gson.JsonElement;
import
cz.muni.ics.edirex.cbioondemandK8S.model.IdentifierCRD
;
import
io.kubernetes.client.JSON
;
import
io.kubernetes.client.util.Yaml
;
import
org.springframework.scheduling.support.CronSequenceGenerator
;
import
org.springframework.stereotype.Component
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.time.Duration
;
import
java.time.ZonedDateTime
;
import
java.util.Date
;
...
...
@@ -31,6 +27,9 @@ import static com.cronutils.model.field.expression.FieldExpressionFactory.on;
*/
@Component
public
class
Utils
{
public
static
final
long
ONE_MINUTE_IN_MILLIS
=
60000
;
public
static
final
long
HOUR
=
ONE_MINUTE_IN_MILLIS
*
60
;
public
static
final
long
FIVE_MINUTES
=
60
*
5
;
private
static
Gson
gson
=
new
Gson
();
...
...
cbioondemandK8S/src/main/java/cz/muni/ics/edirex/cbioondemandK8S/api/API.java
View file @
decbbc45
...
...
@@ -63,6 +63,9 @@ public class API {
@GetMapping
(
"/cbioondemands"
)
public
ResponseEntity
listInstancesForUser
(
User
user
){
List
<
Instance
>
instances
=
cBioOnDemand
.
listInstancesForUser
(
user
);
if
(
instances
==
null
){
return
new
ResponseEntity
<>(
HttpStatus
.
INTERNAL_SERVER_ERROR
);
}
return
new
ResponseEntity
<>(
instances
,
HttpStatus
.
OK
);
}
}
cbioondemandK8S/src/main/java/cz/muni/ics/edirex/cbioondemandK8S/service/KubernetesImpl.java
View file @
decbbc45
...
...
@@ -23,9 +23,7 @@ import java.util.UUID;
@Service
public
class
KubernetesImpl
implements
CBioOnDemandService
{
static
final
long
ONE_MINUTE_IN_MILLIS
=
60000
;
private
static
final
long
FIVE_MINUTES
=
60
*
5
;
private
final
long
HOUR
=
ONE_MINUTE_IN_MILLIS
*
60
;
private
final
long
TIME_TO_LIVE
=
Utils
.
HOUR
;
private
KubernetesCalls
api
;
private
RoutingAAI
routing
;
...
...
@@ -38,8 +36,8 @@ public class KubernetesImpl implements CBioOnDemandService {
private
IdentifierCRD
identifier
;
private
final
String
NAMESPACE
=
"cbio-on-demand"
;
private
final
String
LABELS
=
"app=cbio, type=ondemand"
;
private
final
String
DBLABELS
=
"app=cbioDB, type=ondemand"
;
private
final
String
APP_
LABELS
=
"app=cbio, type=ondemand"
;
private
final
String
DB
_
LABELS
=
"app=cbioDB, type=ondemand"
;
public
KubernetesImpl
(
KubernetesCalls
api
,
RoutingAAI
routing
)
throws
IOException
{
this
.
api
=
api
;
...
...
@@ -75,7 +73,7 @@ public class KubernetesImpl implements CBioOnDemandService {
fallBack
(
hostname
,
cbioService
);
return
null
;
}
return
new
Instance
(
instanceID
,
user
,
HOUR
,
url
,
Status
.
creating
);
return
new
Instance
(
instanceID
,
user
,
TIME_TO_LIVE
,
url
,
Status
.
creating
);
}
private
void
fallBack
(
String
hostname
,
String
cbioService
)
{
...
...
@@ -86,7 +84,7 @@ public class KubernetesImpl implements CBioOnDemandService {
}
public
Instance
status
(
Instance
instance
){
String
labels
=
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
String
labels
=
APP_
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
List
<
V1beta1CronJob
>
result
=
api
.
getCroneJobs
(
labels
,
NAMESPACE
);
if
(
result
.
size
()!=
1
)
...
...
@@ -106,7 +104,7 @@ public class KubernetesImpl implements CBioOnDemandService {
if
(!
statusDecided
(
status
)){
instance
.
fillReport
(
timeToExpire
,
status
);
}
else
{
if
(
timeToExpire
<
FIVE_MINUTES
){
if
(
timeToExpire
<
Utils
.
FIVE_MINUTES
){
instance
.
fillReport
(
timeToExpire
,
Status
.
removing
);
}
else
{
...
...
@@ -128,13 +126,15 @@ public class KubernetesImpl implements CBioOnDemandService {
}
public
Instance
extend
(
Instance
instance
){
String
labels
=
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
String
labels
=
APP_
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
return
updateCronjob
(
instance
,
labels
);
}
public
List
<
Instance
>
listInstancesForUser
(
User
user
)
{
String
labelsRS
=
LABELS
+
", user="
+
user
.
getUserId
();
String
labelsRS
=
APP_
LABELS
+
", user="
+
user
.
getUserId
();
List
<
V1ReplicaSet
>
result
=
api
.
getReplicaSets
(
labelsRS
,
NAMESPACE
);
if
(
result
==
null
)
return
null
;
if
(
result
.
size
()
==
0
)
return
new
ArrayList
<>();
List
<
Instance
>
returns
=
new
ArrayList
<>();
...
...
@@ -142,7 +142,7 @@ public class KubernetesImpl implements CBioOnDemandService {
for
(
V1ReplicaSet
replicaSet
:
result
){
Map
<
String
,
String
>
labels
=
replicaSet
.
getMetadata
().
getLabels
();
String
label
=
LABELS
+
", user="
+
user
.
getUserId
()
+
", instance="
+
String
label
=
APP_
LABELS
+
", user="
+
user
.
getUserId
()
+
", instance="
+
replicaSet
.
getMetadata
().
getLabels
().
get
(
"instance"
);
long
expireTime
=
getExpireDate
(
label
);
...
...
@@ -197,7 +197,7 @@ public class KubernetesImpl implements CBioOnDemandService {
V1beta1CronJob
job
=
Utils
.
deepCopy
(
cronJob
,
V1beta1CronJob
.
class
);
addLabelsAndENV
(
job
,
userID
,
instanceID
);
Date
now
=
new
Date
();
setSchedule
(
job
,
now
.
getTime
()
+
HOUR
);
setSchedule
(
job
,
now
.
getTime
()
+
TIME_TO_LIVE
);
V1beta1CronJob
result
=
api
.
createCroneJob
(
job
,
NAMESPACE
);
if
(
result
!=
null
)
return
result
.
getMetadata
().
getName
();
...
...
@@ -358,7 +358,7 @@ public class KubernetesImpl implements CBioOnDemandService {
}
private
boolean
deleteRemoveJob
(
Instance
instance
)
{
String
labels
=
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
String
labels
=
APP_
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
List
<
V1beta1CronJob
>
result
=
api
.
getCroneJobs
(
labels
,
NAMESPACE
);
if
(
result
==
null
)
return
false
;
...
...
@@ -369,10 +369,10 @@ public class KubernetesImpl implements CBioOnDemandService {
}
private
boolean
deleteServices
(
Instance
instance
)
{
String
labels
=
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
String
labels
=
APP_
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
boolean
cbioService
=
deleteService
(
labels
);
String
dbLabels
=
DBLABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
String
dbLabels
=
DB
_
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
boolean
dbService
=
deleteService
(
dbLabels
);
return
cbioService
&&
dbService
;
...
...
@@ -391,10 +391,10 @@ public class KubernetesImpl implements CBioOnDemandService {
}
private
boolean
deleteReplicaSets
(
Instance
instance
)
{
String
labels
=
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
String
labels
=
APP_
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
boolean
cbioRS
=
deleteReplicaSet
(
labels
);
String
dbLabels
=
DBLABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
String
dbLabels
=
DB
_
LABELS
+
", user="
+
instance
.
getUser
().
getUserId
()
+
", instance="
+
instance
.
getId
();
boolean
dbRS
=
deleteReplicaSet
(
dbLabels
);
return
cbioRS
&&
dbRS
;
...
...
Write
Preview
Supports
Markdown
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