Search in sources :

Example 6 with PUT

use of javax.ws.rs.PUT in project kafka by apache.

the class ConnectorsResource method putConnectorConfig.

@PUT
@Path("/{connector}/config")
public Response putConnectorConfig(@PathParam("connector") final String connector, @QueryParam("forward") final Boolean forward, final Map<String, String> connectorConfig) throws Throwable {
    FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>();
    String includedName = connectorConfig.get(ConnectorConfig.NAME_CONFIG);
    if (includedName != null) {
        if (!includedName.equals(connector))
            throw new BadRequestException("Connector name configuration (" + includedName + ") doesn't match connector name in the URL (" + connector + ")");
    } else {
        connectorConfig.put(ConnectorConfig.NAME_CONFIG, connector);
    }
    herder.putConnectorConfig(connector, connectorConfig, true, cb);
    Herder.Created<ConnectorInfo> createdInfo = completeOrForwardRequest(cb, "/connectors/" + connector + "/config", "PUT", connectorConfig, new TypeReference<ConnectorInfo>() {
    }, new CreatedConnectorInfoTranslator(), forward);
    Response.ResponseBuilder response;
    if (createdInfo.created())
        response = Response.created(URI.create("/connectors/" + connector));
    else
        response = Response.ok();
    return response.entity(createdInfo.result()).build();
}
Also used : Response(javax.ws.rs.core.Response) ConnectorInfo(org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo) BadRequestException(javax.ws.rs.BadRequestException) Herder(org.apache.kafka.connect.runtime.Herder) FutureCallback(org.apache.kafka.connect.util.FutureCallback) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 7 with PUT

use of javax.ws.rs.PUT in project zeppelin by apache.

the class NotebookRepoRestApi method updateRepoSetting.

/**
   * Update a specific note repo.
   *
   * @param message
   * @param settingId
   * @return
   */
@PUT
@ZeppelinApi
public Response updateRepoSetting(String payload) {
    if (StringUtils.isBlank(payload)) {
        return new JsonResponse<>(Status.NOT_FOUND, "", Collections.emptyMap()).build();
    }
    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
    NotebookRepoSettingsRequest newSettings = NotebookRepoSettingsRequest.EMPTY;
    try {
        newSettings = gson.fromJson(payload, NotebookRepoSettingsRequest.class);
    } catch (JsonSyntaxException e) {
        LOG.error("Cannot update notebook repo settings", e);
        return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload structure")).build();
    }
    if (NotebookRepoSettingsRequest.isEmpty(newSettings)) {
        LOG.error("Invalid property");
        return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload")).build();
    }
    LOG.info("User {} is going to change repo setting", subject.getUser());
    NotebookRepoWithSettings updatedSettings = noteRepos.updateNotebookRepo(newSettings.name, newSettings.settings, subject);
    if (!updatedSettings.isEmpty()) {
        LOG.info("Broadcasting note list to user {}", subject.getUser());
        notebookWsServer.broadcastReloadedNoteList(subject, null);
    }
    return new JsonResponse<>(Status.OK, "", updatedSettings).build();
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) NotebookRepoWithSettings(org.apache.zeppelin.notebook.repo.NotebookRepoWithSettings) NotebookRepoSettingsRequest(org.apache.zeppelin.rest.message.NotebookRepoSettingsRequest) AuthenticationInfo(org.apache.zeppelin.user.AuthenticationInfo) JsonResponse(org.apache.zeppelin.server.JsonResponse) ZeppelinApi(org.apache.zeppelin.annotation.ZeppelinApi) PUT(javax.ws.rs.PUT)

Example 8 with PUT

use of javax.ws.rs.PUT in project zookeeper by apache.

the class ZNodeResource method setZNodeAsOctet.

@PUT
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
public void setZNodeAsOctet(@PathParam("path") String path, @DefaultValue("-1") @QueryParam("version") String versionParam, @DefaultValue("false") @QueryParam("null") String setNull, @Context UriInfo ui, byte[] data) throws InterruptedException, KeeperException {
    ensurePathNotNull(path);
    int version;
    try {
        version = Integer.parseInt(versionParam);
    } catch (NumberFormatException e) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).entity(new ZError(ui.getRequestUri().toString(), path + " bad version " + versionParam)).build());
    }
    if (setNull.equals("true")) {
        data = null;
    }
    zk.setData(path, data, version);
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ZError(org.apache.zookeeper.server.jersey.jaxb.ZError) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 9 with PUT

use of javax.ws.rs.PUT in project che by eclipse.

the class ProjectService method updateFile.

@PUT
@Path("/file/{path:.*}")
@Consumes({ MediaType.MEDIA_TYPE_WILDCARD })
@ApiOperation(value = "Update file", notes = "Update an existing file with new content")
@ApiResponses({ @ApiResponse(code = 200, message = ""), @ApiResponse(code = 403, message = "User not authorized to call this operation"), @ApiResponse(code = 404, message = "Not found"), @ApiResponse(code = 500, message = "Internal Server Error") })
public Response updateFile(@ApiParam(value = "Full path to a file", required = true) @PathParam("path") String path, InputStream content) throws NotFoundException, ForbiddenException, ServerException {
    final FileEntry file = projectManager.asFile(path);
    if (file == null) {
        throw new NotFoundException("File not found for " + path);
    }
    file.updateContent(content);
    eventService.publish(new ProjectItemModifiedEvent(ProjectItemModifiedEvent.EventType.UPDATED, workspace, file.getProject(), file.getPath().toString(), false));
    return Response.ok().build();
}
Also used : ProjectItemModifiedEvent(org.eclipse.che.api.project.server.notification.ProjectItemModifiedEvent) NotFoundException(org.eclipse.che.api.core.NotFoundException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Example 10 with PUT

use of javax.ws.rs.PUT in project che by eclipse.

the class WorkspaceService method updateCommand.

@PUT
@Path("/{id}/command/{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace command by replacing the command with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The command successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the workspace"), @ApiResponse(code = 404, message = "The workspace or the command not found"), @ApiResponse(code = 409, message = "The Command with such name already exists"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateCommand(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the command") @PathParam("name") String cmdName, @ApiParam(value = "The command update", required = true) CommandDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
    requiredNotNull(update, "Command update");
    final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
    final List<CommandImpl> commands = workspace.getConfig().getCommands();
    if (!commands.removeIf(cmd -> cmd.getName().equals(cmdName))) {
        throw new NotFoundException(format("Workspace '%s' doesn't contain command '%s'", id, cmdName));
    }
    commands.add(new CommandImpl(update));
    validator.validateConfig(workspace.getConfig());
    return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(workspace.getId(), workspace)), getServiceContext());
}
Also used : CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) EnvironmentImpl(org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ApiParam(io.swagger.annotations.ApiParam) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Service(org.eclipse.che.api.core.rest.Service) Consumes(javax.ws.rs.Consumes) Example(io.swagger.annotations.Example) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) WsAgentHealthChecker(org.eclipse.che.api.agent.server.WsAgentHealthChecker) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) ImmutableMap(com.google.common.collect.ImmutableMap) LINK_REL_GET_WORKSPACES(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_GET_WORKSPACES) NOT_FOUND(javax.ws.rs.core.Response.Status.NOT_FOUND) DtoFactory.newDto(org.eclipse.che.dto.server.DtoFactory.newDto) WsAgentHealthStateDto(org.eclipse.che.api.workspace.shared.dto.WsAgentHealthStateDto) LINK_REL_GET_BY_NAMESPACE(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_GET_BY_NAMESPACE) String.format(java.lang.String.format) SnapshotDto(org.eclipse.che.api.machine.shared.dto.SnapshotDto) List(java.util.List) BadRequestException(org.eclipse.che.api.core.BadRequestException) DtoConverter.asDto(org.eclipse.che.api.workspace.server.DtoConverter.asDto) Response(javax.ws.rs.core.Response) EnvironmentRecipeDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentRecipeDto) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) CommandDto(org.eclipse.che.api.machine.shared.dto.CommandDto) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) WorkspaceDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceDto) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) EnvironmentDto(org.eclipse.che.api.workspace.shared.dto.EnvironmentDto) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ConflictException(org.eclipse.che.api.core.ConflictException) Api(io.swagger.annotations.Api) Named(javax.inject.Named) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink) Collections.emptyMap(java.util.Collections.emptyMap) POST(javax.ws.rs.POST) ProjectConfigDto(org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto) WorkspaceStatus(org.eclipse.che.api.core.model.workspace.WorkspaceStatus) WorkspaceConfigDto(org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto) CHE_WORKSPACE_AUTO_START(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_START) Maps(com.google.common.collect.Maps) NotFoundException(org.eclipse.che.api.core.NotFoundException) Collectors.toList(java.util.stream.Collectors.toList) MachineImpl(org.eclipse.che.api.machine.server.model.impl.MachineImpl) ServerException(org.eclipse.che.api.core.ServerException) ApiResponse(io.swagger.annotations.ApiResponse) ExampleProperty(io.swagger.annotations.ExampleProperty) CommandImpl(org.eclipse.che.api.machine.server.model.impl.CommandImpl) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) CHE_WORKSPACE_AUTO_SNAPSHOT(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_SNAPSHOT) PUT(javax.ws.rs.PUT) CHE_WORKSPACE_AUTO_RESTORE(org.eclipse.che.api.workspace.shared.Constants.CHE_WORKSPACE_AUTO_RESTORE) LINK_REL_CREATE_WORKSPACE(org.eclipse.che.api.workspace.shared.Constants.LINK_REL_CREATE_WORKSPACE) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

PUT (javax.ws.rs.PUT)203 Path (javax.ws.rs.Path)172 Consumes (javax.ws.rs.Consumes)108 Produces (javax.ws.rs.Produces)72 ApiOperation (io.swagger.annotations.ApiOperation)70 ApiResponses (io.swagger.annotations.ApiResponses)53 Timed (com.codahale.metrics.annotation.Timed)36 AuditEvent (org.graylog2.audit.jersey.AuditEvent)36 URI (java.net.URI)24 Response (javax.ws.rs.core.Response)23 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)19 IOException (java.io.IOException)18 BeanWrapper (org.springframework.beans.BeanWrapper)16 BadRequestException (javax.ws.rs.BadRequestException)14 NotFoundException (javax.ws.rs.NotFoundException)14 WebApplicationException (javax.ws.rs.WebApplicationException)12 UriBuilder (javax.ws.rs.core.UriBuilder)12 UUID (java.util.UUID)11 GET (javax.ws.rs.GET)11 POST (javax.ws.rs.POST)11