@Inject public ImageStreamService(ClientFactory clientFactory) { this.getTagUrlTemplate = clientFactory.getClientInfo().getOpenshiftEndpoint() + "/namespaces/{namespace}/imagestreamtags/{imageStream}:{tag}"; this.clientFactory = clientFactory; }
@GET @Path("/{imageStream}/tag/{imageStreamTag}") @Produces(MediaType.APPLICATION_JSON) public ImageStreamTag getImageStreamTag( @PathParam("namespace") String namespace, @PathParam("imageStream") String imageStream, @PathParam("imageStreamTag") String imageStreamTag) throws UnauthorizedException, ServerException { URL url; try { url = UriBuilder.fromPath(getTagUrlTemplate) .buildFromMap( ImmutableMap.of( "namespace", namespace, "imageStream", imageStream, "tag", imageStreamTag)) .toURL(); } catch (MalformedURLException e) { throw new ServerException("Unable to get image stream tag. " + e.getMessage(), e); } try { final String response = clientFactory.getHttpClient().get(url, IHttpClient.DEFAULT_READ_TIMEOUT); return DtoFactory.getInstance().createDtoFromJson(response, ImageStreamTag.class); } catch (SocketTimeoutException e) { throw new ServerException("Unable to get image stream tag. " + e.getMessage(), e); } }
@GET @Path("/{imageStream}") @Produces(MediaType.APPLICATION_JSON) public ImageStream getImageStream( @PathParam("namespace") String namespace, @PathParam("imageStream") String imageStream) throws UnauthorizedException, ServerException { return toDto( ImageStream.class, clientFactory.getOpenshiftClient().get(ResourceKind.IMAGE_STREAM, imageStream, namespace)); }
@PUT @Path("/{imageStream}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ImageStream updateImageStream( @PathParam("namespace") String namespace, @PathParam("imageStream") String imageStreamName, ImageStream imageStream) throws ForbiddenException, UnauthorizedException, ServerException { if (!imageStreamName.equals(imageStream.getMetadata().getName())) { throw new ForbiddenException("Name of resources can read only access mode"); } final IClient client = clientFactory.getOpenshiftClient(); return toDto(ImageStream.class, client.update(toOpenshiftResource(client, imageStream))); }
@GET @Produces(MediaType.APPLICATION_JSON) public List<ImageStream> getImageStreams( @PathParam("namespace") String namespace, @QueryParam("application") String application) throws UnauthorizedException, ServerException { Map<String, String> labels = new HashMap<>(); if (application != null) { labels.put("application", application); } List<IImageStream> imageStreams = clientFactory.getOpenshiftClient().list(ResourceKind.IMAGE_STREAM, namespace, labels); return imageStreams .stream() .map(imageStream -> toDto(ImageStream.class, imageStream)) .collect(Collectors.toList()); }
@POST @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public ImageStream createImageStream( @PathParam("namespace") String namespace, ImageStream imageStream) throws BadRequestException, UnauthorizedException, ServerException { if (imageStream.getKind() == null) { imageStream.setKind(ResourceKind.IMAGE_STREAM); } if (!ResourceKind.IMAGE_STREAM.equals(imageStream.getKind())) { throw new BadRequestException( imageStream.getKind() + " cannot be handled as a " + ResourceKind.IMAGE_STREAM); } final IClient client = clientFactory.getOpenshiftClient(); final IImageStream openshiftImageStream = toOpenshiftResource(client, imageStream); return toDto(ImageStream.class, client.create(openshiftImageStream, namespace)); }