Skip to content

Commit

Permalink
new msd api to create transport policy (#2422)
Browse files Browse the repository at this point in the history
Signed-off-by: Abhijeet V <31417623+abvaidya@users.noreply.github.com>
  • Loading branch information
abvaidya authored Nov 20, 2023
1 parent d5f3cc0 commit 7d79152
Show file tree
Hide file tree
Showing 12 changed files with 666 additions and 9 deletions.
38 changes: 38 additions & 0 deletions clients/go/msd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,44 @@ func (client MSDClient) GetTransportPolicyRulesByDomain(domainName DomainName, m
}
}

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

func (client MSDClient) GetWorkloadsByService(domainName DomainName, serviceName EntityName, matchingTag string) (*Workloads, string, error) {
var data *Workloads
headers := map[string]string{
Expand Down
175 changes: 175 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.

39 changes: 36 additions & 3 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 @@ -251,6 +251,41 @@ public TransportPolicyRules getTransportPolicyRulesByDomain(String domainName, S
}
}

public TransportPolicyRules putTransportPolicy(String domainName, String serviceName, TransportPolicyRequest payload) throws URISyntaxException, IOException {
UriTemplateBuilder uriTemplateBuilder = new UriTemplateBuilder(baseUrl, "/domain/{domainName}/service/{serviceName}/transportpolicy")
.resolveTemplate("domainName", domainName)
.resolveTemplate("serviceName", serviceName);
URIBuilder uriBuilder = new URIBuilder(uriTemplateBuilder.getUri());
HttpEntity httpEntity = new StringEntity(jsonMapper.writeValueAsString(payload), 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:
case 200:
if (code == 204) {
return null;
}
return jsonMapper.readValue(httpResponseEntity.getContent(), TransportPolicyRules.class);
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 getWorkloadsByService(String domainName, String serviceName, String matchingTag, java.util.Map<String, java.util.List<String>> headers) throws URISyntaxException, IOException {
UriTemplateBuilder uriTemplateBuilder = new UriTemplateBuilder(baseUrl, "/domain/{domainName}/service/{serviceName}/workloads")
.resolveTemplate("domainName", domainName)
Expand Down
Loading

0 comments on commit 7d79152

Please sign in to comment.