-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1038 from CrowleyRajapakse/master
Adding retrieving API Project Zip for JMS event
- Loading branch information
Showing
21 changed files
with
1,260 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[controlPlane] | ||
enabled = true | ||
serviceURL = "https://wso2apim:9443/" | ||
username = "admin" | ||
password = "admin" | ||
environmentLabels = ["Default"] | ||
skipSSLVerification = true | ||
[controlPlane.brokerConnectionParameters] | ||
eventListeningEndpoints = ["amqp://admin:admin@wso2apim:5672?retries='10'&connectdelay='30'"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# The logging configuration for Adapter | ||
|
||
## Adapter root Level configurations | ||
|
||
logLevel = "INFO" # LogLevels can be "DEBG", "FATL", "ERRO", "WARN", "INFO", "PANC" | ||
LogFormat = "TEXT" # Values can be "JSON", "TEXT" | ||
|
||
[rotation] | ||
MaxSize = 10 # In MegaBytes (MB) | ||
MaxBackups = 3 | ||
MaxAge = 2 # In days | ||
Compress = true | ||
|
||
## Adapter package Level configurations | ||
|
||
[[pkg]] | ||
name = "github.com/wso2/apk/adapter/internal/adapter" | ||
logLevel = "INFO" # LogLevels can be "DEBG", "FATL", "ERRO", "WARN", "INFO", "PANC" | ||
|
||
[[pkg]] | ||
name = "github.com/wso2/apk/adapter/internal/oasparser" | ||
logLevel = "INFO" | ||
|
||
|
||
# The logging configuration for Router | ||
|
||
[accessLogs] | ||
enable = false | ||
format = "[%START_TIME%] '%REQ(:METHOD)% %DYNAMIC_METADATA(envoy.filters.http.ext_authz:originalPath)% %REQ(:PATH)% %PROTOCOL%' %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% '%REQ(X-FORWARDED-FOR)%' '%REQ(USER-AGENT)%' '%REQ(X-REQUEST-ID)%' '%REQ(:AUTHORITY)%' '%UPSTREAM_HOST%'\n" | ||
|
||
[wireLogs] | ||
enable = false | ||
include = ["Headers", "Body", "Trailers"] | ||
|
||
# [[pkg]] | ||
# name = "github.com/wso2/apk/Adapter/pkg/xds" | ||
# logLevel = "INFO" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
apim-apk-agent/internal/notifier/deployment_notifier.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* Licensed 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 notifier | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
"time" | ||
|
||
"github.com/wso2/apk/adapter/pkg/logging" | ||
"github.com/wso2/product-apim-tooling/apim-apk-agent/config" | ||
logger "github.com/wso2/product-apim-tooling/apim-apk-agent/internal/loggers" | ||
"github.com/wso2/product-apim-tooling/apim-apk-agent/pkg/auth" | ||
"github.com/wso2/product-apim-tooling/apim-apk-agent/pkg/tlsutils" | ||
) | ||
|
||
const ( | ||
deployedRevisionEP string = "internal/data/v1/apis/deployed-revisions" | ||
unDeployedRevisionEP string = "internal/data/v1/apis/undeployed-revision" | ||
authBasic string = "Basic " | ||
authHeader string = "Authorization" | ||
contentTypeHeader string = "Content-Type" | ||
) | ||
|
||
// UpdateDeployedRevisions create the DeployedAPIRevision object | ||
func UpdateDeployedRevisions(apiID string, revisionID int, envs []string, vhost string) *DeployedAPIRevision { | ||
revisions := &DeployedAPIRevision{ | ||
APIID: apiID, | ||
RevisionID: revisionID, | ||
EnvInfo: []DeployedEnvInfo{}, | ||
} | ||
for _, env := range envs { | ||
info := DeployedEnvInfo{ | ||
Name: env, | ||
VHost: vhost, | ||
} | ||
revisions.EnvInfo = append(revisions.EnvInfo, info) | ||
} | ||
return revisions | ||
} | ||
|
||
// SendRevisionUpdateAck sends succeeded revision deployment acknowledgement to the control plane | ||
func SendRevisionUpdateAck(deployedRevisionList []*DeployedAPIRevision) { | ||
conf, _ := config.ReadConfigs() | ||
cpConfigs := conf.ControlPlane | ||
|
||
if len(deployedRevisionList) < 1 || !cpConfigs.Enabled || !cpConfigs.SendRevisionUpdate { | ||
return | ||
} | ||
|
||
logger.LoggerNotifier.Debugf("Revision deployed message is sending to Control plane") | ||
|
||
revisionEP := cpConfigs.ServiceURL | ||
if strings.HasSuffix(revisionEP, "/") { | ||
revisionEP += deployedRevisionEP | ||
} else { | ||
revisionEP += "/" + deployedRevisionEP | ||
} | ||
|
||
jsonValue, _ := json.Marshal(deployedRevisionList) | ||
|
||
// Setting authorization header | ||
basicAuth := authBasic + auth.GetBasicAuth(cpConfigs.Username, cpConfigs.Password) | ||
|
||
logger.LoggerNotifier.Debugf("Revision deployed message sending to Control plane: %v", string(jsonValue)) | ||
|
||
// Adding 3 retries for revision update sending | ||
retries := 0 | ||
for retries < 3 { | ||
retries++ | ||
|
||
req, _ := http.NewRequest("PATCH", revisionEP, bytes.NewBuffer(jsonValue)) | ||
req.Header.Set(authHeader, basicAuth) | ||
req.Header.Set(contentTypeHeader, "application/json") | ||
resp, err := tlsutils.InvokeControlPlane(req, cpConfigs.SkipSSLVerification) | ||
|
||
success := true | ||
if err != nil { | ||
logger.LoggerNotifier.ErrorC(logging.ErrorDetails{ | ||
Message: fmt.Sprintf("Error response from %v for attempt %v : %v", revisionEP, retries, err.Error()), | ||
Severity: logging.MAJOR, | ||
ErrorCode: 2100, | ||
}) | ||
success = false | ||
} | ||
if resp != nil && resp.StatusCode != http.StatusOK { | ||
logger.LoggerNotifier.ErrorC(logging.ErrorDetails{ | ||
Message: fmt.Sprintf("Error response status code %v from %v for attempt %v", resp.StatusCode, revisionEP, retries), | ||
Severity: logging.MINOR, | ||
ErrorCode: 2101, | ||
}) | ||
success = false | ||
} | ||
if success { | ||
logger.LoggerNotifier.Infof("Revision deployed message sent to Control plane for attempt %v", retries) | ||
break | ||
} | ||
} | ||
} | ||
|
||
// SendRevisionUndeployAck - send the undeployed revision acknowledgement to control plane | ||
func SendRevisionUndeployAck(apiUUID string, revisionUUID string, environment string) { | ||
conf, _ := config.ReadConfigs() | ||
cpConfigs := conf.ControlPlane | ||
if apiUUID == "" || revisionUUID == "" || environment == "" || !cpConfigs.Enabled || !cpConfigs.SendRevisionUpdate { | ||
return | ||
} | ||
revisionEP := cpConfigs.ServiceURL | ||
if strings.HasSuffix(revisionEP, "/") { | ||
revisionEP += unDeployedRevisionEP | ||
} else { | ||
revisionEP += "/" + unDeployedRevisionEP | ||
} | ||
|
||
removedRevision := UnDeployedAPIRevision{ | ||
APIUUID: apiUUID, | ||
RevisionUUID: revisionUUID, | ||
Environment: environment, | ||
} | ||
|
||
jsonValue, _ := json.Marshal(removedRevision) | ||
basicAuth := authBasic + auth.GetBasicAuth(cpConfigs.Username, cpConfigs.Password) | ||
retries := 0 | ||
for retries < 3 { | ||
retries++ | ||
req, _ := http.NewRequest("POST", revisionEP, bytes.NewBuffer(jsonValue)) | ||
req.Header.Set(authHeader, basicAuth) | ||
req.Header.Set(contentTypeHeader, "application/json") | ||
resp, err := tlsutils.InvokeControlPlane(req, cpConfigs.SkipSSLVerification) | ||
|
||
success := true | ||
if err != nil { | ||
logger.LoggerNotifier.ErrorC(logging.ErrorDetails{ | ||
Message: fmt.Sprintf("Error response from %s for attempt %d : %v", revisionEP, retries, err.Error()), | ||
Severity: logging.MAJOR, | ||
ErrorCode: 2100, | ||
}) | ||
success = false | ||
} | ||
if resp != nil && resp.StatusCode != http.StatusOK { | ||
logger.LoggerNotifier.ErrorC(logging.ErrorDetails{ | ||
Message: fmt.Sprintf("Error response status code %v from %s for attempt %d", resp.StatusCode, revisionEP, retries), | ||
Severity: logging.MINOR, | ||
ErrorCode: 2101, | ||
}) | ||
success = false | ||
} | ||
if success { | ||
logger.LoggerNotifier.Infof("Revision un-deployed message sent to Control plane for attempt %d", retries) | ||
break | ||
} | ||
time.Sleep(2 * time.Second) | ||
} | ||
} |
Oops, something went wrong.