Search in sources :

Example 6 with TopologyVersion

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;
}
Also used : Response(javax.ws.rs.core.Response) TopologyVersion(com.hortonworks.streamline.streams.catalog.TopologyVersion) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 7 with TopologyVersion

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());
    }
}
Also used : TopologyVersion(com.hortonworks.streamline.streams.catalog.TopologyVersion) Topology(com.hortonworks.streamline.streams.catalog.Topology)

Example 8 with TopologyVersion

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;
    }
}
Also used : TopologyVersion(com.hortonworks.streamline.streams.catalog.TopologyVersion) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) EntityNotFoundException(com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException) StormNotReachableException(com.hortonworks.streamline.streams.storm.common.StormNotReachableException) TopologyNotAliveException(com.hortonworks.streamline.streams.exception.TopologyNotAliveException) StreamingEngineNotReachableException(com.hortonworks.streamline.common.exception.service.exception.server.StreamingEngineNotReachableException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 9 with TopologyVersion

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());
}
Also used : TopologyVersion(com.hortonworks.streamline.streams.catalog.TopologyVersion) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 10 with TopologyVersion

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;
}
Also used : TopologyVersion(com.hortonworks.streamline.streams.catalog.TopologyVersion)

Aggregations

TopologyVersion (com.hortonworks.streamline.streams.catalog.TopologyVersion)13 Timed (com.codahale.metrics.annotation.Timed)3 Path (javax.ws.rs.Path)3 StorableKey (com.hortonworks.registries.storage.StorableKey)2 Topology (com.hortonworks.streamline.streams.catalog.Topology)2 ArrayList (java.util.ArrayList)2 POST (javax.ws.rs.POST)2 QueryParam (com.hortonworks.registries.common.QueryParam)1 FileStorage (com.hortonworks.registries.common.util.FileStorage)1 StorageManager (com.hortonworks.registries.storage.StorageManager)1 ManagedTransaction (com.hortonworks.registries.storage.transaction.ManagedTransaction)1 BadRequestException (com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException)1 EntityNotFoundException (com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException)1 StreamingEngineNotReachableException (com.hortonworks.streamline.common.exception.service.exception.server.StreamingEngineNotReachableException)1 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)1 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)1 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)1 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)1 MLModelRegistryClient (com.hortonworks.streamline.registries.model.client.MLModelRegistryClient)1 Projection (com.hortonworks.streamline.streams.catalog.Projection)1