From 880f84135d1e370f21d392429f84ec7c2e74772e Mon Sep 17 00:00:00 2001 From: Sajinie Date: Tue, 3 Dec 2024 13:30:05 +0530 Subject: [PATCH 1/3] CLI support to activate/deactivate inbound endpoints --- cmd/cmd/activate/inboundendpoint.go | 64 +++++++++++++++++++ cmd/cmd/deactivate/inboundendpoint.go | 64 +++++++++++++++++++ cmd/impl/getInboundEndpoints.go | 4 +- cmd/impl/inboundEndpoint.go | 38 +++++++++++ cmd/shell-completions/mi_bash_completion.sh | 60 +++++++++++++++++ cmd/shell-completions/mi_bash_completion.sh-e | 60 +++++++++++++++++ .../artifactUtils/inboundEndpointUtils.go | 2 + 7 files changed, 291 insertions(+), 1 deletion(-) create mode 100644 cmd/cmd/activate/inboundendpoint.go create mode 100644 cmd/cmd/deactivate/inboundendpoint.go create mode 100644 cmd/impl/inboundEndpoint.go diff --git a/cmd/cmd/activate/inboundendpoint.go b/cmd/cmd/activate/inboundendpoint.go new file mode 100644 index 000000000..26a73bac5 --- /dev/null +++ b/cmd/cmd/activate/inboundendpoint.go @@ -0,0 +1,64 @@ +/* +* Copyright (c) WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 LLC. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package activate + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/wso2/product-mi-tooling/cmd/credentials" + impl "github.com/wso2/product-mi-tooling/cmd/impl" + miUtils "github.com/wso2/product-mi-tooling/cmd/utils" +) + +var activateInboundEndpointCmdEnvironment string + +const artifactInboundEndpoint = "inbound endpoint" +const activateInboundEndpointCmdLiteral = "inbound-endpoint [inboundendpoint-name]" + +var activateInboundEndpointCmd = &cobra.Command{ + Use: activateInboundEndpointCmdLiteral, + Short: generateActivateCmdShortDescForArtifact(artifactInboundEndpoint), + Long: generateActivateCmdLongDescForArtifact(artifactInboundEndpoint, "inboundendpoint-name"), + Example: generateActivateCmdExamplesForArtifact(artifactInboundEndpoint, miUtils.GetTrimmedCmdLiteral(activateInboundEndpointCmdLiteral), "TestInboundEndpoint"), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + handleActivateInboundEndpointCmdArguments(args) + }, +} + +func init() { + ActivateCmd.AddCommand(activateInboundEndpointCmd) + setEnvFlag(activateInboundEndpointCmd, &activateInboundEndpointCmdEnvironment, artifactInboundEndpoint) +} + +func handleActivateInboundEndpointCmdArguments(args []string) { + printActivateCmdVerboseLog(miUtils.GetTrimmedCmdLiteral(activateInboundEndpointCmdLiteral)) + credentials.HandleMissingCredentials(activateInboundEndpointCmdEnvironment) + executeActivateInboundEndpoint(args[0]) +} + +func executeActivateInboundEndpoint(inboundEndpointName string) { + resp, err := impl.ActivateInboundEndpoint(activateInboundEndpointCmdEnvironment, inboundEndpointName) + if err != nil { + printErrorForArtifact(artifactInboundEndpoint, inboundEndpointName, err) + } else { + fmt.Println(resp) + } +} diff --git a/cmd/cmd/deactivate/inboundendpoint.go b/cmd/cmd/deactivate/inboundendpoint.go new file mode 100644 index 000000000..325c0b504 --- /dev/null +++ b/cmd/cmd/deactivate/inboundendpoint.go @@ -0,0 +1,64 @@ +/* +* Copyright (c) WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 LLC. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package deactivate + +import ( + "fmt" + + "github.com/spf13/cobra" + "github.com/wso2/product-mi-tooling/cmd/credentials" + "github.com/wso2/product-mi-tooling/cmd/impl" + miUtils "github.com/wso2/product-mi-tooling/cmd/utils" +) + +var deactivateInboundEndpointCmdEnvironment string + +const artifactInboundEndpoint = "inbound endpoint" +const deactivateInboundEndpointCmdLiteral = "inbound-endpoint [inboundendpoint-name]" + +var deactivateInboundEndpointCmd = &cobra.Command{ + Use: deactivateInboundEndpointCmdLiteral, + Short: generateDeactivateCmdShortDescForArtifact(artifactInboundEndpoint), + Long: generateDeactivateCmdLongDescForArtifact(artifactInboundEndpoint, "inboundendpoint-name"), + Example: generateDeactivateCmdExamplesForArtifact(artifactInboundEndpoint, miUtils.GetTrimmedCmdLiteral(deactivateInboundEndpointCmdLiteral), "TestInboundEndpoint"), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + handleDeactivateInboundEndpointCmdArguments(args) + }, +} + +func init() { + DeactivateCmd.AddCommand(deactivateInboundEndpointCmd) + setEnvFlag(deactivateInboundEndpointCmd, &deactivateInboundEndpointCmdEnvironment, artifactInboundEndpoint) +} + +func handleDeactivateInboundEndpointCmdArguments(args []string) { + printDeactivateCmdVerboseLog(miUtils.GetTrimmedCmdLiteral(deactivateInboundEndpointCmdLiteral)) + credentials.HandleMissingCredentials(deactivateInboundEndpointCmdEnvironment) + executeDeactivateInboundEndpoint(args[0]) +} + +func executeDeactivateInboundEndpoint(inboundEndpointName string) { + resp, err := impl.DeactivateInboundEndpoint(deactivateInboundEndpointCmdEnvironment, inboundEndpointName) + if err != nil { + printErrorForArtifact(artifactInboundEndpoint, inboundEndpointName, err) + } else { + fmt.Println(resp) + } +} diff --git a/cmd/impl/getInboundEndpoints.go b/cmd/impl/getInboundEndpoints.go index ea44d5f22..e1ac267be 100644 --- a/cmd/impl/getInboundEndpoints.go +++ b/cmd/impl/getInboundEndpoints.go @@ -31,11 +31,12 @@ import ( ) const ( - defaultInboundEndpointListTableFormat = "table {{.Name}}\t{{.Type}}" + defaultInboundEndpointListTableFormat = "table {{.Name}}\t{{.Type}}\t{{.Status}}" defaultInboundEndpointDetailedFormat = "detail Name - {{.Name}}\n" + "Type - {{.Type}}\n" + "Stats - {{.Stats}}\n" + "Tracing - {{.Tracing}}\n" + + "Status - {{.Status}}\n" + "Parameters :\n" + "NAME\tVALUE\n" + "{{range .Parameters}}{{.Name}}\t{{.Value}}\n{{end}}" @@ -68,6 +69,7 @@ func PrintInboundEndpointList(inboundEPList *artifactUtils.InboundEndpointList, inboundEPListTableHeaders := map[string]string{ "Name": nameHeader, "Type": typeHeader, + "Status": statusHeader, } if err := inboundEPListContext.Write(renderer, inboundEPListTableHeaders); err != nil { fmt.Println("Error executing template:", err.Error()) diff --git a/cmd/impl/inboundEndpoint.go b/cmd/impl/inboundEndpoint.go new file mode 100644 index 000000000..a9a8493a1 --- /dev/null +++ b/cmd/impl/inboundEndpoint.go @@ -0,0 +1,38 @@ +/* +* Copyright (c) WSO2 LLC. (http://www.wso2.org) All Rights Reserved. +* +* WSO2 LLC. licenses this file to you under the Apache License, +* Version 2.0 (the "License"); you may not use this file except +* in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. + */ + +package impl + +import ( + "github.com/wso2/product-mi-tooling/cmd/utils" +) + +// ActivateInboundEndpoint activates an inbound endpoint deployed in the micro integrator in a given environment +func ActivateInboundEndpoint(env, inboundEndpointName string) (interface{}, error) { + return updateInboundEndpointServiceState(env, inboundEndpointName, "active") +} + +// DeactivateInboundEndpoint deactivates an inbound endpoint deployed in the micro integrator in a given environment +func DeactivateInboundEndpoint(env, inboundEndpointName string) (interface{}, error) { + return updateInboundEndpointServiceState(env, inboundEndpointName, "inactive") +} + +func updateInboundEndpointServiceState(env, inboundEndpointName, state string) (interface{}, error) { + url := utils.GetMIManagementEndpointOfResource(utils.MiManagementInboundEndpointResource, env, utils.MainConfigFilePath) + return updateArtifactState(url, inboundEndpointName, state, env) +} diff --git a/cmd/shell-completions/mi_bash_completion.sh b/cmd/shell-completions/mi_bash_completion.sh index 211c726be..ca231da3f 100644 --- a/cmd/shell-completions/mi_bash_completion.sh +++ b/cmd/shell-completions/mi_bash_completion.sh @@ -1470,6 +1470,35 @@ _mi_activate_endpoint() noun_aliases=() } +_mi_activate_inbound-endpoint() +{ + last_command="mi_activate_inbound-endpoint" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--environment=") + two_word_flags+=("--environment") + two_word_flags+=("-e") + local_nonpersistent_flags+=("--environment=") + flags+=("--insecure") + flags+=("-k") + flags+=("--verbose") + + must_have_one_flag=() + must_have_one_flag+=("--environment=") + must_have_one_flag+=("-e") + must_have_one_noun=() + noun_aliases=() +} + _mi_activate_message-processor() { last_command="mi_activate_message-processor" @@ -1536,6 +1565,7 @@ _mi_activate() commands=() commands+=("endpoint") + commands+=("inbound-endpoint") commands+=("message-processor") commands+=("proxy-service") @@ -1583,6 +1613,35 @@ _mi_deactivate_endpoint() noun_aliases=() } +_mi_deactivate_inbound-endpoint() +{ + last_command="mi_deactivate_inbound-endpoint" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--environment=") + two_word_flags+=("--environment") + two_word_flags+=("-e") + local_nonpersistent_flags+=("--environment=") + flags+=("--insecure") + flags+=("-k") + flags+=("--verbose") + + must_have_one_flag=() + must_have_one_flag+=("--environment=") + must_have_one_flag+=("-e") + must_have_one_noun=() + noun_aliases=() +} + _mi_deactivate_message-processor() { last_command="mi_deactivate_message-processor" @@ -1649,6 +1708,7 @@ _mi_deactivate() commands=() commands+=("endpoint") + commands+=("inbound-endpoint") commands+=("message-processor") commands+=("proxy-service") diff --git a/cmd/shell-completions/mi_bash_completion.sh-e b/cmd/shell-completions/mi_bash_completion.sh-e index 211c726be..ca231da3f 100644 --- a/cmd/shell-completions/mi_bash_completion.sh-e +++ b/cmd/shell-completions/mi_bash_completion.sh-e @@ -1470,6 +1470,35 @@ _mi_activate_endpoint() noun_aliases=() } +_mi_activate_inbound-endpoint() +{ + last_command="mi_activate_inbound-endpoint" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--environment=") + two_word_flags+=("--environment") + two_word_flags+=("-e") + local_nonpersistent_flags+=("--environment=") + flags+=("--insecure") + flags+=("-k") + flags+=("--verbose") + + must_have_one_flag=() + must_have_one_flag+=("--environment=") + must_have_one_flag+=("-e") + must_have_one_noun=() + noun_aliases=() +} + _mi_activate_message-processor() { last_command="mi_activate_message-processor" @@ -1536,6 +1565,7 @@ _mi_activate() commands=() commands+=("endpoint") + commands+=("inbound-endpoint") commands+=("message-processor") commands+=("proxy-service") @@ -1583,6 +1613,35 @@ _mi_deactivate_endpoint() noun_aliases=() } +_mi_deactivate_inbound-endpoint() +{ + last_command="mi_deactivate_inbound-endpoint" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--environment=") + two_word_flags+=("--environment") + two_word_flags+=("-e") + local_nonpersistent_flags+=("--environment=") + flags+=("--insecure") + flags+=("-k") + flags+=("--verbose") + + must_have_one_flag=() + must_have_one_flag+=("--environment=") + must_have_one_flag+=("-e") + must_have_one_noun=() + noun_aliases=() +} + _mi_deactivate_message-processor() { last_command="mi_deactivate_message-processor" @@ -1649,6 +1708,7 @@ _mi_deactivate() commands=() commands+=("endpoint") + commands+=("inbound-endpoint") commands+=("message-processor") commands+=("proxy-service") diff --git a/cmd/utils/artifactUtils/inboundEndpointUtils.go b/cmd/utils/artifactUtils/inboundEndpointUtils.go index 9609cd86d..d86c6dde2 100644 --- a/cmd/utils/artifactUtils/inboundEndpointUtils.go +++ b/cmd/utils/artifactUtils/inboundEndpointUtils.go @@ -8,6 +8,7 @@ type InboundEndpointList struct { type InboundEndpointSummary struct { Name string `json:"name"` Type string `json:"protocol"` + Status string `json:"status"` } type InboundEndpoint struct { @@ -16,6 +17,7 @@ type InboundEndpoint struct { Stats string `json:"stats"` Tracing string `json:"tracing"` Parameters []Parameter `json:"parameters"` + Status string `json:"status"` } type Parameter struct { From ace25b5ee7f9682971917f4a34a439e85bf30aa5 Mon Sep 17 00:00:00 2001 From: Sajinie Date: Tue, 3 Dec 2024 13:39:18 +0530 Subject: [PATCH 2/3] Add activate/deactivate inbound endpoint support to integration control plane --- .../micro/integrator/delegates/InboundEndpointDelegate.java | 4 ++++ .../web-app/src/pages/InboundEndpoints.js | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/monitoring-dashboard/components/org.wso2.ei.dashboard.core/src/main/java/org/wso2/ei/dashboard/micro/integrator/delegates/InboundEndpointDelegate.java b/monitoring-dashboard/components/org.wso2.ei.dashboard.core/src/main/java/org/wso2/ei/dashboard/micro/integrator/delegates/InboundEndpointDelegate.java index 66d2253e7..f9f764da9 100644 --- a/monitoring-dashboard/components/org.wso2.ei.dashboard.core/src/main/java/org/wso2/ei/dashboard/micro/integrator/delegates/InboundEndpointDelegate.java +++ b/monitoring-dashboard/components/org.wso2.ei.dashboard.core/src/main/java/org/wso2/ei/dashboard/micro/integrator/delegates/InboundEndpointDelegate.java @@ -67,6 +67,10 @@ private boolean updateInboundEndpoint(String groupId, ArtifactUpdateRequest requ String trace = request.isValue() ? "enable" : "disable"; payload.addProperty("trace", trace); } + if (request.getType().equals("status")) { + String status = request.isValue() ? "active" : "inactive"; + payload.addProperty("status", status); + } return DelegatesUtil.updateArtifact(Constants.INBOUND_ENDPOINTS, groupId, request, payload); } diff --git a/monitoring-dashboard/components/org.wso2.micro.integrator.dashboard.web/web-app/src/pages/InboundEndpoints.js b/monitoring-dashboard/components/org.wso2.micro.integrator.dashboard.web/web-app/src/pages/InboundEndpoints.js index b85f78669..4219c4cee 100644 --- a/monitoring-dashboard/components/org.wso2.micro.integrator.dashboard.web/web-app/src/pages/InboundEndpoints.js +++ b/monitoring-dashboard/components/org.wso2.micro.integrator.dashboard.web/web-app/src/pages/InboundEndpoints.js @@ -28,7 +28,8 @@ export default function InboundEndpoints() { headCells: [ {id: 'name', label: 'Inbound Endpoint Name'}, {id: 'nodes', label: 'Nodes'}, - {id: 'protocol', label: 'Protocol'}], + {id: 'protocol', label: 'Protocol'}, + {id: 'status', label: 'Status'}], tableOrderBy: 'name' }); From 99603ae1ab436037eef9d0e0b4609fea1fe20c90 Mon Sep 17 00:00:00 2001 From: Sajinie Date: Fri, 13 Dec 2024 20:24:05 +0530 Subject: [PATCH 3/3] Enable status switch button only for File inbound endpoints --- .../web-app/src/commons/TableRowCreator.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/monitoring-dashboard/components/org.wso2.micro.integrator.dashboard.web/web-app/src/commons/TableRowCreator.js b/monitoring-dashboard/components/org.wso2.micro.integrator.dashboard.web/web-app/src/commons/TableRowCreator.js index ba24b9fb0..d523aa9be 100644 --- a/monitoring-dashboard/components/org.wso2.micro.integrator.dashboard.web/web-app/src/commons/TableRowCreator.js +++ b/monitoring-dashboard/components/org.wso2.micro.integrator.dashboard.web/web-app/src/commons/TableRowCreator.js @@ -103,7 +103,7 @@ export default function TableRowCreator(props) { // Message Processors case 'status': return {data.nodes.map(node=>)} + nodeId={node.nodeId} status={node.details.status === 'active' ? true : false} retrieveData={retrieveData} isDisabled={pageId === 'inbound-endpoints' ? (node.details.protocol === 'file'? false: true) : false}/>)} // Apis case 'url': @@ -231,10 +231,10 @@ function StatusIcon(props) { } function SwitchStatusCell(props) { - const { pageId, artifactName, nodeId, status, retrieveData} = props; + const { pageId, artifactName, nodeId, status, retrieveData, isDisabled} = props; var isActive = status; const globalGroupId = useSelector(state => state.groupId); - const hasEditPermission = AuthManager.hasEditPermission(); + const shouldBeDisabled = !AuthManager.hasEditPermission() || isDisabled; const changeState = () => { isActive = !isActive @@ -255,7 +255,7 @@ function SwitchStatusCell(props) { }); } - return + return } function LogConfigLevelDropDown(props) {