private List<Long> getOutputStreamIds(TopologySource topologySource) { List<Long> streamIds = new ArrayList<>(); if (topologySource != null) { QueryParam qp1 = new QueryParam(TopologySourceStreamMap.FIELD_SOURCE_ID, String.valueOf(topologySource.getId())); QueryParam qp2 = new QueryParam(TopologySourceStreamMap.FIELD_VERSION_ID, String.valueOf(topologySource.getVersionId())); for (TopologySourceStreamMap mapping : listTopologySourceStreamMapping(ImmutableList.of(qp1, qp2))) { streamIds.add(mapping.getStreamId()); } } return streamIds; }
private List<TopologyStream> getOutputStreams(TopologySource topologySource) { List<TopologyStream> streams = new ArrayList<>(); if (topologySource != null) { QueryParam qp1 = new QueryParam(TopologySourceStreamMap.FIELD_SOURCE_ID, String.valueOf(topologySource.getId())); QueryParam qp2 = new QueryParam(TopologySourceStreamMap.FIELD_VERSION_ID, String.valueOf(topologySource.getVersionId())); for (TopologySourceStreamMap mapping : listTopologySourceStreamMapping(ImmutableList.of(qp1, qp2))) { TopologyStream topologyStream = getStreamInfo(topologySource.getTopologyId(), mapping.getStreamId(), topologySource.getVersionId()); if (topologyStream != null) { streams.add(topologyStream); } } } return streams; }
private void validateTopologySource(TopologySource topologySource) { StorageUtils.ensureUnique(topologySource, this::listTopologySources, QueryParam.params(TopologySource.TOPOLOGYID, topologySource.getTopologyId().toString(), TopologySource.VERSIONID, topologySource.getVersionId().toString(), TopologySource.NAME, topologySource.getName())); }
@POST @Path("/topologies/{topologyId}/testcases/{testCaseId}/sources") public Response addTestRunCaseSource(@PathParam("topologyId") Long topologyId, @PathParam("testCaseId") Long testCaseId, TopologyTestRunCaseSource testRunCaseSource, @Context SecurityContext securityContext) { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, WRITE); TopologySource topologySource = getAssociatedTopologySource(topologyId, testCaseId, testRunCaseSource.getSourceId()); testRunCaseSource.setVersionId(topologySource.getVersionId()); TopologyTestRunCaseSource addedCaseSource = catalogService.addTopologyTestRunCaseSource(testRunCaseSource); return WSUtils.respondEntity(addedCaseSource, CREATED); }
private void addSourceStreamMapping(TopologySource topologySource, List<Long> streamIds) { for (Long outputStreamId : streamIds) { dao.<TopologySourceStreamMap>add(new TopologySourceStreamMap(topologySource.getId(), topologySource.getVersionId(), outputStreamId)); } }
@PUT @Path("/topologies/{topologyId}/testcases/{testCaseId}/sources/{id}") public Response addOrUpdateTestRunCaseSource(@PathParam("topologyId") Long topologyId, @PathParam("testCaseId") Long testCaseId, @PathParam("id") Long id, TopologyTestRunCaseSource testRunCaseSource, @Context SecurityContext securityContext) { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, Topology.NAMESPACE, topologyId, WRITE); testRunCaseSource.setId(id); testRunCaseSource.setTestCaseId(testCaseId); TopologySource topologySource = getAssociatedTopologySource(topologyId, testCaseId, testRunCaseSource.getSourceId()); testRunCaseSource.setVersionId(topologySource.getVersionId()); TopologyTestRunCaseSource updatedCase = catalogService.addOrUpdateTopologyTestRunCaseSource(testRunCaseSource.getId(), testRunCaseSource); return WSUtils.respondEntity(updatedCase, OK); }
private TopologySource getAssociatedTopologySource(Long topologyId, Long testCaseId, Long topologySourceId) { TopologyTestRunCase testCase = catalogService.getTopologyTestRunCase(topologyId, testCaseId); if (testCase == null) { throw EntityNotFoundException.byId("Topology test case with topology id " + topologyId + " and test case id " + testCaseId); } TopologySource topologySource = catalogService.getTopologySource(topologyId, topologySourceId, testCase.getVersionId()); if (topologySource == null) { throw EntityNotFoundException.byId("Topology source with topology id " + topologyId + " and version id " + testCase.getVersionId()); } else if (!testCase.getVersionId().equals(topologySource.getVersionId())) { throw new IllegalStateException("Test case and topology source point to the different version id: " + "version id of test case: " + testCase.getVersionId() + " / " + "version id of topology source: " + topologySource.getVersionId()); } return topologySource; }
private void removeSourceStreamMapping(TopologySource topologySource, List<Long> streamIds) { if (topologySource != null) { for (Long outputStreamId : streamIds) { TopologySourceStreamMap mapping = new TopologySourceStreamMap( topologySource.getId(), topologySource.getVersionId(), outputStreamId); dao.<TopologySourceStreamMap>remove(mapping.getStorableKey()); } } }