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

DIscover additional instances to MSD, with dynamic/static workloads #2660

Merged
merged 5 commits into from
Aug 1, 2024
Merged
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
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