Skip to content

Commit

Permalink
add method for subscribed mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Mar 22, 2024
1 parent 1c3647a commit 8fc1829
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public abstract class AConnectorClient {

// structure < ident, mapping >
// public Map<String, Mapping> subscribedMappings = new HashMap<>();
public List<String> subscribedMappings = new ArrayList<>();
@Getter
private List<String> subscribedMappings = new ArrayList<>();

private Instant start = Instant.now();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
@Setter
@NoArgsConstructor
public class MappingSubscribed implements Serializable {
public MappingSubscribed(String ident) {
this.ident = ident;
this.connectorSubscribed = new ArrayList<>();
}

@NotNull
public String ident;
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import dynamic.mapping.model.TreeNode;
import dynamic.mapping.model.Mapping;
import dynamic.mapping.model.MappingStatus;
import dynamic.mapping.model.MappingSubscribed;

@Slf4j
@RestController
Expand Down Expand Up @@ -453,6 +454,33 @@ public ResponseEntity<Map<String, Integer>> getActiveSubscriptions(@PathVariable

}

@RequestMapping(value = "/monitoring/mappings", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Map<String,MappingSubscribed>> getMappingsSubscribed() {
String tenant = contextService.getContext().getTenant();
Map<String,MappingSubscribed> mappingsSubscribed = new HashMap<>();
try {
HashMap<String, AConnectorClient> connectorMap = connectorRegistry
.getClientsForTenant(tenant);
if (connectorMap != null) {
for (AConnectorClient client : connectorMap.values()) {
ConnectorConfiguration cleanedConfiguration = getCleanedConfig(client.getConnectorConfiguration());
List<String> subscribedMappings = client.getSubscribedMappings();
subscribedMappings.forEach(ident -> {
MappingSubscribed mappingSubscribed = mappingsSubscribed.getOrDefault(ident, new MappingSubscribed(ident));
mappingSubscribed.getConnectorSubscribed().add(cleanedConfiguration);
mappingsSubscribed.put(ident, mappingSubscribed);
});
}
}

log.info("Tenant {} - Get active subscriptions!", tenant);
return ResponseEntity.status(HttpStatus.OK).body(mappingsSubscribed);
} catch (ConnectorRegistryException e) {
throw new RuntimeException(e);
}

}

@RequestMapping(value = "/mapping", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<Mapping>> getMappings() {
String tenant = contextService.getContext().getTenant();
Expand Down Expand Up @@ -610,7 +638,8 @@ public ResponseEntity<Extension> getProcessorExtension(@PathVariable String exte
public ResponseEntity<Extension> deleteProcessorExtension(@PathVariable String extensionName) {
String tenant = contextService.getContext().getTenant();
if (!userHasMappingAdminRole()) {
log.error("Tenant {} - Insufficient Permission, user does not have required permission to access this API", tenant);
log.error("Tenant {} - Insufficient Permission, user does not have required permission to access this API",
tenant);
throw new ResponseStatusException(HttpStatus.FORBIDDEN,
"Insufficient Permission, user does not have required permission to access this API");
}
Expand Down

0 comments on commit 8fc1829

Please sign in to comment.