Skip to content

Commit

Permalink
merge #2660 from master to jetty 1.12.x branch (#2675)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Avetisyan <hga@yahooinc.com>
  • Loading branch information
havetisyan authored Aug 6, 2024
1 parent 39662bd commit b3f8680
Show file tree
Hide file tree
Showing 9 changed files with 587 additions and 1 deletion.
58 changes: 58 additions & 0 deletions clients/go/msd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,64 @@ func (client MSDClient) GetWorkloadsByDomainAndService(request *BulkWorkloadRequ
}
}

func (client MSDClient) PutCompositeInstance(domainName DomainName, serviceName EntityName, instance *CompositeInstance) error {
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/workload/discover/instance"
contentBytes, err := json.Marshal(instance)
if err != nil {
return err
}
resp, err := client.httpPut(url, nil, contentBytes)
if err != nil {
return err
}
defer resp.Body.Close()
switch resp.StatusCode {
case 204:
return nil
default:
var errobj rdl.ResourceError
contentBytes, err = io.ReadAll(resp.Body)
if err != nil {
return err
}
json.Unmarshal(contentBytes, &errobj)
if errobj.Code == 0 {
errobj.Code = resp.StatusCode
}
if errobj.Message == "" {
errobj.Message = string(contentBytes)
}
return errobj
}
}

func (client MSDClient) DeleteCompositeInstance(domainName DomainName, serviceName EntityName, instance SimpleName) error {
url := client.URL + "/domain/" + fmt.Sprint(domainName) + "/service/" + fmt.Sprint(serviceName) + "/workload/discover/instance/" + fmt.Sprint(instance)
resp, err := client.httpDelete(url, nil)
if err != nil {
return err
}
defer resp.Body.Close()
switch resp.StatusCode {
case 204:
return nil
default:
var errobj rdl.ResourceError
contentBytes, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
json.Unmarshal(contentBytes, &errobj)
if errobj.Code == 0 {
errobj.Code = resp.StatusCode
}
if errobj.Message == "" {
errobj.Message = string(contentBytes)
}
return errobj
}
}

func (client MSDClient) EvaluateNetworkPolicyChange(detail *NetworkPolicyChangeImpactRequest) (*NetworkPolicyChangeImpactResponse, error) {
var data *NetworkPolicyChangeImpactResponse
url := client.URL + "/transportpolicy/evaluatenetworkpolicychange"
Expand Down
105 changes: 105 additions & 0 deletions clients/go/msd/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions clients/go/msd/msd_schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,67 @@ public BulkWorkloadResponse getWorkloadsByDomainAndService(BulkWorkloadRequest r
}
}

public Workloads putCompositeInstance(String domainName, String serviceName, CompositeInstance instance) throws URISyntaxException, IOException {
UriTemplateBuilder uriTemplateBuilder = new UriTemplateBuilder(baseUrl, "/domain/{domainName}/service/{serviceName}/workload/discover/instance")
.resolveTemplate("domainName", domainName)
.resolveTemplate("serviceName", serviceName);
URIBuilder uriBuilder = new URIBuilder(uriTemplateBuilder.getUri());
HttpEntity httpEntity = new StringEntity(jsonMapper.writeValueAsString(instance), ContentType.APPLICATION_JSON);
HttpUriRequest httpUriRequest = RequestBuilder.put()
.setUri(uriBuilder.build())
.setEntity(httpEntity)
.build();
if (credsHeader != null) {
httpUriRequest.addHeader(credsHeader, credsToken);
}
HttpEntity httpResponseEntity = null;
try (CloseableHttpResponse httpResponse = client.execute(httpUriRequest, httpContext)) {
int code = httpResponse.getStatusLine().getStatusCode();
httpResponseEntity = httpResponse.getEntity();
switch (code) {
case 204:
return null;
default:
final String errorData = (httpResponseEntity == null) ? null : EntityUtils.toString(httpResponseEntity);
throw (errorData != null && !errorData.isEmpty())
? new ResourceException(code, jsonMapper.readValue(errorData, ResourceError.class))
: new ResourceException(code);
}
} finally {
EntityUtils.consumeQuietly(httpResponseEntity);
}
}

public Workloads deleteCompositeInstance(String domainName, String serviceName, String instance) throws URISyntaxException, IOException {
UriTemplateBuilder uriTemplateBuilder = new UriTemplateBuilder(baseUrl, "/domain/{domainName}/service/{serviceName}/workload/discover/instance/{instance}")
.resolveTemplate("domainName", domainName)
.resolveTemplate("serviceName", serviceName)
.resolveTemplate("instance", instance);
URIBuilder uriBuilder = new URIBuilder(uriTemplateBuilder.getUri());
HttpUriRequest httpUriRequest = RequestBuilder.delete()
.setUri(uriBuilder.build())
.build();
if (credsHeader != null) {
httpUriRequest.addHeader(credsHeader, credsToken);
}
HttpEntity httpResponseEntity = null;
try (CloseableHttpResponse httpResponse = client.execute(httpUriRequest, httpContext)) {
int code = httpResponse.getStatusLine().getStatusCode();
httpResponseEntity = httpResponse.getEntity();
switch (code) {
case 204:
return null;
default:
final String errorData = (httpResponseEntity == null) ? null : EntityUtils.toString(httpResponseEntity);
throw (errorData != null && !errorData.isEmpty())
? new ResourceException(code, jsonMapper.readValue(errorData, ResourceError.class))
: new ResourceException(code);
}
} finally {
EntityUtils.consumeQuietly(httpResponseEntity);
}
}

public NetworkPolicyChangeImpactResponse evaluateNetworkPolicyChange(NetworkPolicyChangeImpactRequest detail) throws URISyntaxException, IOException {
UriTemplateBuilder uriTemplateBuilder = new UriTemplateBuilder(baseUrl, "/transportpolicy/evaluatenetworkpolicychange");
URIBuilder uriBuilder = new URIBuilder(uriTemplateBuilder.getUri());
Expand Down
Loading

0 comments on commit b3f8680

Please sign in to comment.