Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
[#46] relations between services via "linkedServices"
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Pozzi committed Nov 11, 2019
1 parent d075149 commit 09e44c3
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/main/java/de/bonndan/nivio/input/rancher1/APIWalker.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import de.bonndan.nivio.ProcessingException;
import de.bonndan.nivio.input.dto.ItemDescription;
import de.bonndan.nivio.input.dto.RelationDescription;
import de.bonndan.nivio.input.dto.SourceReference;
import io.rancher.Rancher;
import io.rancher.service.ProjectService;
Expand All @@ -21,6 +22,12 @@
import static de.bonndan.nivio.input.rancher1.ItemDescriptionFactoryRancher1API.API_ACCESS_KEY;
import static de.bonndan.nivio.input.rancher1.ItemDescriptionFactoryRancher1API.API_SECRET_KEY;

/**
* Gathers projects, stacks and services from a Rancher 1.6 API
*
*
*
*/
class APIWalker {

private Rancher rancher;
Expand Down Expand Up @@ -61,10 +68,10 @@ private Map<String, Stack> getStacksById(String accountId) {
StackService stackService = rancher.type(StackService.class);
Map<String, Stack> stacks = new HashMap<>();
try {
stackService.list().execute().body().getData().stream()
stackService.list().execute().body().getData().stream()
.filter(stack -> stack.getAccountId().equals(accountId))
.forEach(stack -> stacks.put(stack.getId(), stack));
return stacks;
return stacks;
} catch (IOException e) {
throw new ProcessingException(reference.getLandscapeDescription(), "Could not access Rancher API", e);
}
Expand All @@ -88,9 +95,24 @@ private List<ItemDescription> asDescriptions(List<Service> data, final Map<Strin

data.forEach(service -> {
ItemDescription item = new ItemDescription();
item.setIdentifier(service.getName());
item.setIdentifier(service.getId());
item.setName(service.getName());
item.setScale(String.valueOf(service.getScale()));
Stack stack = stacks.get(service.getStackId());
item.setGroup(stack.getName());
if (stack != null)
item.setGroup(stack.getName());

if (service.getLinkedServices() != null) {
service.getLinkedServices().forEach((key, value) -> {
RelationDescription rd = new RelationDescription();
rd.setSource((String) value);
rd.setTarget(item.getIdentifier());
item.addRelation(rd);
});
}

//TODO data/metadata to labels

descriptions.add(item);
});

Expand Down

0 comments on commit 09e44c3

Please sign in to comment.