Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Microservice control #1091

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2022, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
Expand All @@ -24,9 +24,24 @@

class MicroservicesController < ModelController
def initialize
super()
@model_class = OpenC3::MicroserviceModel
end

def start
return unless authorization('system')
microservice = @model_class.get_model(name: params[:id], scope: params[:scope])
OpenC3::Logger.info("#{params[:id]} started", scope: params[:scope], user: username())
# TODO: How to access operator and start microservice?
end

def stop
return unless authorization('system')
microservice = @model_class.get_model(name: params[:id], scope: params[:scope])
OpenC3::Logger.info("#{params[:id]} stopped", scope: params[:scope], user: username())
# TODO: How to access operator and stop microservice?
end

def traefik
result = {}
result['http'] = {}
Expand Down
2 changes: 2 additions & 0 deletions openc3-cosmos-cmd-tlm-api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
get '/microservices/:id', to: 'microservices#show', id: /[^\/]+/
match '/microservices/:id', to: 'microservices#update', id: /[^\/]+/, via: [:patch, :put]
delete '/microservices/:id', to: 'microservices#destroy', id: /[^\/]+/
post '/microservices/:id/start', to: 'microservices#start', id: /[^\/]+/
post '/microservices/:id/stop', to: 'microservices#stop', id: /[^\/]+/

resources :process_status, only: [:index]
get '/process_status/:id', to: 'process_status#show', id: /[^\/]+/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# GNU Affero General Public License for more details.

# Modified by OpenC3, Inc.
# All changes Copyright 2023, OpenC3, Inc.
# All changes Copyright 2024, OpenC3, Inc.
# All Rights Reserved
#
# This file may also be used under the terms of a commercial license
Expand All @@ -22,6 +22,13 @@

<template>
<div>
<v-alert
v-model="showAlert"
dismissible
transition="scale-transition"
:type="alertType"
>{{ alert }}</v-alert
>
<v-list class="list" data-test="microserviceList">
<div v-for="microservice in microservices" :key="microservice">
<v-list-item>
Expand Down Expand Up @@ -52,6 +59,34 @@
</v-list-item-icon>
</div>
</div>
<v-list-item-icon class="mr-3">
<v-tooltip bottom>
<template v-slot:activator="{ on, attrs }">
<v-icon
@click="startMicroservice(microservice)"
v-bind="attrs"
v-on="on"
>
mdi-play
</v-icon>
</template>
<span>Start Microservice</span>
</v-tooltip>
</v-list-item-icon>
<v-list-item-icon>
<v-tooltip bottom>
<template v-slot:activator="{ on, attrs }">
<v-icon
@click="stopMicroservice(microservice)"
v-bind="attrs"
v-on="on"
>
mdi-stop
</v-icon>
</template>
<span>Stop Microservice</span>
</v-tooltip>
</v-list-item-icon>
<v-list-item-icon>
<v-tooltip bottom>
<template v-slot:activator="{ on, attrs }">
Expand Down Expand Up @@ -108,6 +143,9 @@ export default {
dialogTitle: '',
showDialog: false,
showError: false,
alert: '',
alertType: 'success',
showAlert: false,
}
},
mounted() {
Expand All @@ -122,6 +160,20 @@ export default {
this.microservices = response.data
})
},
startMicroservice: function (name) {
Api.post(`/openc3-api/microservices/${name}/start`).then((response) => {
this.alert = `Started ${name}`
this.alertType = 'success'
this.showAlert = true
})
},
stopMicroservice: function (name) {
Api.post(`/openc3-api/microservices/${name}/stop`).then((response) => {
this.alert = `Stopped ${name}`
this.alertType = 'success'
this.showAlert = true
})
},
showMicroservice: function (name) {
Api.get(`/openc3-api/microservices/${name}`).then((response) => {
this.microservice_id = name
Expand Down
Loading