Skip to content

Commit a5b3400

Browse files
add description for app
1 parent 968558f commit a5b3400

File tree

3 files changed

+89
-37
lines changed

3 files changed

+89
-37
lines changed

controllers/manager_controller.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,29 @@ def handle_desktop_GET( self, args ):
519519
return resource
520520

521521
if args[1]=="pod":
522+
523+
if len(args)==2 :
524+
# list container for a desktop
525+
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container
526+
applications = oc.od.composer.list_applications_by_name_and_type(desktop_name, 'pod_application')
527+
return applications
528+
529+
if len(args)==3:
530+
app_name = args[2]
531+
# describe container for a desktop
532+
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container/container_id
533+
application = oc.od.composer.describe_application_byname( desktop_name, app_name )
534+
return application
535+
522536
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/pod/pod_id/resources_usage
523-
if len(args)==4 and args[3]=="resources_usage":
537+
if len(args)==4 and args[3]=="resources_usage":
524538
#
525539
# args[0] -> desktop_name
526540
# args[1] -> pod
527541
# args[2] -> pod_name or pod_id
528542
# args[3] -> resources_usage
529543
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/pod/pod_id/resources_usage
530544
pod_name = args[2]
531-
if not isinstance( pod_name, str):
532-
raise cherrypy.HTTPError(status=400, message='Invalid parameters Bad Request')
533545
self.logger.debug(f'get pod resources usage for {desktop_name} {pod_name}')
534546
resource = oc.od.composer.get_pod_resources_usage(desktop_name=desktop_name, pod_name=pod_name)
535547
return resource
@@ -541,16 +553,14 @@ def handle_desktop_GET( self, args ):
541553
if len(args)==2 :
542554
# list container for a desktop
543555
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container
544-
container = oc.od.composer.list_container_byname(desktop_name)
545-
return container
556+
applications = oc.od.composer.list_applications_by_name_and_type(desktop_name, 'ephemeral_container')
557+
return applications
546558

547559
if len(args)==3:
548-
container_id = args[2]
549-
if not isinstance( container_id, str):
550-
raise cherrypy.HTTPError(status=400, message='Invalid parameters Bad Request')
560+
app_name = args[2]
551561
# describe container for a desktop
552562
# /API/manager/desktop/hermes-8a49ca1a-fcc6-4b7b-960f-5a27debd4773/container/container_id
553-
container = oc.od.composer.describe_container( desktop_name, container=container_id )
563+
container = oc.od.composer.describe_application_byname( desktop_name, app_name=app_name )
554564
return container
555565

556566
if len(args)==4 and args[3]=="resources_usage":

oc/od/composer.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,28 @@ def list_container_byname( desktop_name:str ):
225225
raise ODError( status=404, message='desktop not found')
226226
return myOrchestrator.listContainerApps(authinfo, userinfo, myDesktop, services.apps )
227227

228+
229+
def list_applications_by_name_and_type( desktop_name:str, type_of_application:str ):
230+
myOrchestrator = selectOrchestrator()
231+
(authinfo, userinfo, myDesktop) = myOrchestrator.find_userinfo_authinfo_desktop_by_desktop_name( name=desktop_name )
232+
if not isinstance( myDesktop, oc.od.desktop.ODDesktop) :
233+
raise ODError( status=404, message='desktop not found')
234+
if not isinstance( authinfo, AuthInfo) or not isinstance( userinfo, AuthUser) :
235+
raise ODError( status=404, message='desktop not found')
236+
return myOrchestrator.list_application_by_type_of_application(authinfo, userinfo, myDesktop, type_of_application, services.apps )
237+
228238
def describe_desktop_byname( desktop_name:str ):
229239
myOrchestrator = selectOrchestrator()
230240
myPod = myOrchestrator.describe_desktop_byname( desktop_name )
231241
if not isinstance( myPod, dict ):
232242
raise ODError( status=404, message='desktop not found')
233243
return myPod
234244

235-
def describe_container_byname( desktop_name:str , container_id:str ):
236-
myOrchestrator = selectOrchestrator()
237-
container = myOrchestrator.describe_container( desktop_name, container_id )
238-
return container
245+
def describe_application_byname( desktop_name:str, app_name:str ):
246+
myOrchestrator = selectOrchestrator()
247+
(authinfo, userinfo) = myOrchestrator.find_userinfo_authinfo_by_desktop_name( name=desktop_name )
248+
description = myOrchestrator.describe_application( authinfo, userinfo, desktop_name, app_name )
249+
return description
239250

240251
def remove_container_byname(desktop_name:str, container:str):
241252
myOrchestrator = selectOrchestrator()
@@ -420,7 +431,7 @@ def prepareressources( authinfo: AuthInfo, userinfo: AuthUser ):
420431
myOrchestrator.prepareressources( authinfo=authinfo, userinfo=userinfo )
421432

422433

423-
def stopContainerApp(authinfo: AuthInfo, userinfo: AuthUser, podname:str, containerid:str):
434+
def stopContainerApp(authinfo: AuthInfo, userinfo: AuthUser, podname:str, app_name:str):
424435
"""stop container application if the container belongs to the user
425436
Args:
426437
authinfo (AuthInfo): authentification data
@@ -444,7 +455,7 @@ def stopContainerApp(authinfo: AuthInfo, userinfo: AuthUser, podname:str, contai
444455
services.fail2ban.fail_login( userinfo.userid )
445456
raise ODError( status=401, message='stopcontainer::invalid user')
446457

447-
result = myOrchestrator.stopContainerApp( authinfo, userinfo, podname, containerid )
458+
result = myOrchestrator.stopContainerApp( authinfo, userinfo, podname, app_name )
448459
return result
449460

450461

oc/od/orchestrator.py

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,6 @@ def is_instance_app( self, appinstance ):
638638
def execwaitincontainer( self, desktop, command, timeout=1000):
639639
raise NotImplementedError(f"{type(self)}.removedesktop")
640640

641-
def getappinstance( self, authinfo, userinfo, app ):
642-
raise NotImplementedError(f"{type(self)}.getappinstance")
643-
644641
def get_auth_env_dict( self, authinfo, userinfo ):
645642
return {}
646643

@@ -2423,6 +2420,21 @@ def countRunningAppforUser( self, authinfo:AuthInfo, userinfo:AuthUser, myDeskto
24232420
count += len( myappinstance.list(authinfo, userinfo, myDesktop ) )
24242421
return count
24252422

2423+
2424+
def list_application_by_type_of_application( self, authinfo:AuthInfo, userinfo:AuthUser, myDesktop:ODDesktop, application_type:str, apps:ODApps=None ):
2425+
assert isinstance(authinfo, AuthInfo), f"authinfo has invalid type {type(authinfo)}"
2426+
assert isinstance(userinfo, AuthUser), f"userinfo has invalid type {type(userinfo)}"
2427+
assert isinstance(myDesktop, ODDesktop), f"myDesktop has invalid type {type(myDesktop)}"
2428+
self.logger.debug('')
2429+
list_apps = []
2430+
if application_type == self.pod_application :
2431+
myappinstance = ODAppInstanceKubernetesPod( self )
2432+
list_apps += myappinstance.list(authinfo, userinfo, myDesktop, phase_filter=self.all_phases_status, apps=apps)
2433+
if application_type == self.ephemeral_container :
2434+
myappinstance = ODAppInstanceKubernetesEphemeralContainer( self )
2435+
list_apps += myappinstance.list(authinfo, userinfo, myDesktop, phase_filter=self.all_phases_status, apps=apps)
2436+
return list_apps
2437+
24262438
def listContainerApps( self, authinfo:AuthInfo, userinfo:AuthUser, myDesktop:ODDesktop, apps:ODApps=None ):
24272439
"""listContainerApps
24282440
@@ -2491,40 +2503,41 @@ def getAppInstanceKubernetes( self, authinfo:AuthInfo, userinfo:AuthUser, pod_na
24912503

24922504
return myappinstance
24932505

2494-
def logContainerApp( self, authinfo:AuthInfo, userinfo:AuthUser, pod_name:str, containerid:str):
2506+
def logContainerApp( self, authinfo:AuthInfo, userinfo:AuthUser, pod_name:str, app_name:str):
24952507
assert isinstance(pod_name, str), f"podname has invalid type {type(pod_name)}"
24962508
log_app = None
2497-
myappinstance = self.getAppInstanceKubernetes(authinfo, userinfo, pod_name, containerid)
2509+
myappinstance = self.getAppInstanceKubernetes(authinfo, userinfo, pod_name, app_name)
24982510
if isinstance( myappinstance, ODAppInstanceBase ):
2499-
log_app = myappinstance.logContainerApp(pod_name, containerid)
2511+
log_app = myappinstance.logContainerApp(pod_name, app_name)
25002512
return log_app
25012513

2502-
def envContainerApp( self, authinfo:AuthInfo, userinfo:AuthUser, pod_name:str, containerid:str):
2514+
def envContainerApp( self, authinfo:AuthInfo, userinfo:AuthUser, pod_name:str, app_name:str):
25032515
assert isinstance(pod_name, str), f"podname has invalid type {type(pod_name)}"
25042516
env_result = None
2505-
myappinstance = self.getAppInstanceKubernetes(authinfo, userinfo, pod_name, containerid)
2517+
myappinstance = self.getAppInstanceKubernetes(authinfo, userinfo, pod_name, app_name)
25062518
if isinstance( myappinstance, ODAppInstanceBase ):
2507-
env_result = myappinstance.envContainerApp(authinfo, userinfo, pod_name, containerid)
2519+
env_result = myappinstance.envContainerApp(authinfo, userinfo, pod_name, app_name)
25082520
return env_result
25092521

2510-
def stopContainerApp( self, authinfo:AuthInfo, userinfo:AuthUser, pod_name:str, containerid:str)->bool:
2522+
def stopContainerApp( self, authinfo:AuthInfo, userinfo:AuthUser, pod_name:str, app_name:str)->bool:
25112523
assert isinstance(pod_name, str), f"podname has invalid type {type(pod_name)}"
25122524
stop_result = None
2513-
myappinstance = self.getAppInstanceKubernetes(authinfo, userinfo, pod_name, containerid)
2525+
myappinstance = self.getAppInstanceKubernetes(authinfo, userinfo, pod_name, app_name)
25142526
if isinstance( myappinstance, ODAppInstanceBase ):
2515-
stop_result = myappinstance.stop(pod_name, containerid)
2527+
stop_result = myappinstance.stop(pod_name, app_name)
25162528
return stop_result
25172529

2518-
def removeContainerApp( self, authinfo:AuthInfo, userinfo:AuthUser, pod_name:str, containerid:str):
2519-
return self.stopContainerApp( authinfo, userinfo, pod_name, containerid)
2530+
def describe_application( self, authinfo:AuthInfo, userinfo:AuthUser, pod_name:str, app_name:str)->dict:
2531+
assert isinstance(pod_name, str), f"podname has invalid type {type(pod_name)}"
2532+
assert isinstance(app_name, str), f"app_name has invalid type {type(app_name)}"
2533+
app_description = None
2534+
myappinstance = self.getAppInstanceKubernetes(authinfo, userinfo, pod_name, app_name)
2535+
if isinstance( myappinstance, ODAppInstanceBase ):
2536+
app_description = myappinstance.describe(pod_name, app_name)
2537+
return app_description
25202538

2521-
def getappinstance( self, authinfo, userinfo, app ):
2522-
self.logger.debug('')
2523-
for app_class in self.appinstance_classes.values():
2524-
app_object = app_class( orchestrator=self )
2525-
appinstance = app_object.findRunningAppInstanceforUserandImage( authinfo, userinfo, app )
2526-
if app_object.isinstance( appinstance ):
2527-
return appinstance
2539+
def removeContainerApp( self, authinfo:AuthInfo, userinfo:AuthUser, pod_name:str, app_name:str)->bool:
2540+
return self.stopContainerApp( authinfo, userinfo, pod_name, app_name)
25282541

25292542
"""
25302543
def read_configmap( self, name, entry ):
@@ -4452,8 +4465,11 @@ def find_userinfo_authinfo_desktop_by_desktop_name( self, name:str )->tuple:
44524465
# not found
44534466
pass
44544467
return (authinfo,userinfo,myDesktop)
4455-
4468+
44564469
def describe_desktop_byname( self, name:str )->dict:
4470+
return self.describe_pod_byname( name )
4471+
4472+
def describe_pod_byname( self, name:str )->dict:
44574473
"""describe_desktop_byname
44584474
44594475
Args:
@@ -5491,6 +5507,18 @@ def create(self, myDesktop:ODDesktop, app, authinfo:AuthInfo, userinfo:AuthUser=
54915507
return appinstancestatus
54925508
"""
54935509

5510+
def describe( self, pod_name:str, app_name:str ):
5511+
description = None
5512+
pod = self.orchestrator.kubeapi.read_namespaced_pod(namespace=self.orchestrator.namespace,name=pod_name)
5513+
if isinstance( pod, V1Pod ) and \
5514+
isinstance( pod.spec, V1PodSpec ) and \
5515+
isinstance( pod.spec.ephemeral_containers, list):
5516+
for c in pod.spec.ephemeral_containers:
5517+
if isinstance( c, V1EphemeralContainer ) :
5518+
if c.name == app_name:
5519+
description = c.to_dict()
5520+
break
5521+
return description
54945522

54955523
def findRunningAppInstanceforUserandImage( self, authinfo:AuthInfo, userinfo:AuthUser, app):
54965524
self.logger.debug('')
@@ -5561,6 +5589,9 @@ def get_nodeSelector( self ):
55615589
nodeSelector = oc.od.settings.desktop_pod.get(self.type, {}).get('nodeSelector',{})
55625590
return nodeSelector
55635591

5592+
def describe( self, pod_name:str, app_name:str ):
5593+
return self.orchestrator.describe_pod_byname( app_name )
5594+
55645595
def get_appnodeSelector( self, authinfo:AuthInfo, userinfo:AuthUser, app:dict ):
55655596
"""get_appnodeSelector
55665597
get the node selector merged data from

0 commit comments

Comments
 (0)