use of com.hortonworks.streamline.streams.catalog.TopologyVersion in project streamline by hortonworks.
the class TopologyCatalogResource method listTopologyVersions.
@GET
@Path("/topologies/{topologyId}/versions")
@Timed
public Response listTopologyVersions(@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) {
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ);
Collection<TopologyVersion> versionInfos = catalogService.listTopologyVersionInfos(WSUtils.buildTopologyIdAwareQueryParams(topologyId, null));
Response response;
if (versionInfos != null) {
response = WSUtils.respondEntities(versionInfos, OK);
} else {
response = WSUtils.respondEntities(Collections.emptyList(), OK);
}
return response;
}
use of com.hortonworks.streamline.streams.catalog.TopologyVersion in project streamline by hortonworks.
the class TopologyCatalogResource method removeAllTopologyVersions.
private Response removeAllTopologyVersions(Long topologyId) {
Collection<TopologyVersion> versions = catalogService.listTopologyVersionInfos(WSUtils.topologyVersionsQueryParam(topologyId));
Long currentVersionId = catalogService.getCurrentVersionId(topologyId);
Topology res = null;
for (TopologyVersion version : versions) {
Topology removed = catalogService.removeTopology(topologyId, version.getId(), true);
if (removed != null && removed.getVersionId().equals(currentVersionId)) {
res = removed;
}
}
// remove topology state information
catalogService.removeTopologyState(topologyId);
if (res != null) {
return WSUtils.respondEntity(res, OK);
} else {
throw EntityNotFoundException.byId(topologyId.toString());
}
}
use of com.hortonworks.streamline.streams.catalog.TopologyVersion in project streamline by hortonworks.
the class TopologyCatalogResource method saveTopologyVersion.
/**
* {
* "name": "v2",
* "description": "saved before prod deployment"
* }
*/
@POST
@Path("/topologies/{topologyId}/versions/save")
@Timed
public Response saveTopologyVersion(@PathParam("topologyId") Long topologyId, TopologyVersion versionInfo, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_ADMIN);
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ);
Optional<TopologyVersion> currentVersion = Optional.empty();
try {
currentVersion = catalogService.getCurrentTopologyVersionInfo(topologyId);
if (!currentVersion.isPresent()) {
throw new IllegalArgumentException("Current version is not available for topology id: " + topologyId);
}
if (versionInfo == null) {
versionInfo = new TopologyVersion();
}
// update the current version with the new version info.
versionInfo.setTopologyId(topologyId);
Optional<TopologyVersion> latest = catalogService.getLatestVersionInfo(topologyId);
int suffix;
if (latest.isPresent()) {
suffix = latest.get().getVersionNumber() + 1;
} else {
suffix = 1;
}
versionInfo.setName(VERSION_PREFIX + suffix);
if (versionInfo.getDescription() == null) {
versionInfo.setDescription("");
}
TopologyVersion savedVersion = catalogService.addOrUpdateTopologyVersionInfo(currentVersion.get().getId(), versionInfo);
catalogService.cloneTopologyVersion(topologyId, savedVersion.getId());
return WSUtils.respondEntity(savedVersion, CREATED);
} catch (Exception ex) {
// restore the current version
if (currentVersion.isPresent()) {
catalogService.addOrUpdateTopologyVersionInfo(currentVersion.get().getId(), currentVersion.get());
}
throw ex;
}
}
use of com.hortonworks.streamline.streams.catalog.TopologyVersion in project streamline by hortonworks.
the class TopologyCatalogResource method activateTopologyVersion.
@POST
@Path("/topologies/{topologyId}/versions/{versionId}/activate")
@Timed
public Response activateTopologyVersion(@PathParam("topologyId") Long topologyId, @PathParam("versionId") Long versionId, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_ADMIN);
SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ);
Optional<TopologyVersion> currentVersionInfo = catalogService.getCurrentTopologyVersionInfo(topologyId);
if (currentVersionInfo.isPresent() && currentVersionInfo.get().getId().equals(versionId)) {
throw new IllegalArgumentException("Version id " + versionId + " is already the current version");
}
TopologyVersion savedVersion = catalogService.getTopologyVersionInfo(versionId);
if (savedVersion != null) {
catalogService.cloneTopologyVersion(topologyId, savedVersion.getId());
/*
* successfully cloned and set a new current version,
* remove the old current version of topology and version info
*/
if (currentVersionInfo.isPresent()) {
catalogService.removeTopology(topologyId, currentVersionInfo.get().getId(), true);
}
return WSUtils.respondEntity(savedVersion, CREATED);
}
throw EntityNotFoundException.byVersion(topologyId.toString(), versionId.toString());
}
use of com.hortonworks.streamline.streams.catalog.TopologyVersion in project streamline by hortonworks.
the class StreamCatalogServiceTest method createTopologyVersionInfo.
private TopologyVersion createTopologyVersionInfo(Long id, Long topologyId) {
TopologyVersion topologyVersion = new TopologyVersion();
topologyVersion.setId(id);
topologyVersion.setName("name" + id);
topologyVersion.setTopologyId(topologyId);
topologyVersion.setDescription("description" + id);
topologyVersion.setTimestamp(System.currentTimeMillis());
return topologyVersion;
}
Aggregations