@Path("/{containerName}/delete/vip/{vipName}") @DELETE @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @StatusCodes({ @ResponseCode(code = 200, condition = "VIP deleted successfully"), @ResponseCode(code = 404, condition = "The containerName not found"), @ResponseCode(code = 503, condition = "Load balancer service is unavailable"), @ResponseCode(code = 404, condition = "VIP not found"), @ResponseCode(code = 500, condition = "Failed to delete VIP") }) public Response deleteVIP( @PathParam(value = "containerName") String containerName, @PathParam(value = "vipName") String vipName) { if (vipName.isEmpty()) throw new UnsupportedMediaTypeException(RestMessages.INVALIDDATA.toString()); IConfigManager configManager = getConfigManagerService(containerName); if (configManager == null) { throw new ServiceUnavailableException( "Load Balancer" + RestMessages.SERVICEUNAVAILABLE.toString()); } if (!configManager.vipExists(vipName)) throw new ResourceNotFoundException(NBConst.RES_VIP_NOT_FOUND); for (VIP vip : configManager.getAllVIPs()) { if (vip.getName().equals(vipName)) { configManager.deleteVIP(vipName); return Response.ok().build(); } } throw new InternalServerErrorException(NBConst.RES_VIP_DELETION_FAILED); }
@Path("/{containerName}/update/vip") @PUT @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @StatusCodes({ @ResponseCode(code = 201, condition = "VIP updated successfully"), @ResponseCode(code = 404, condition = "The containerName not found"), @ResponseCode(code = 503, condition = "VIP not found"), @ResponseCode(code = 404, condition = "Pool not found"), @ResponseCode(code = 405, condition = "Pool already attached to the VIP"), @ResponseCode(code = 415, condition = "Invalid input name") }) public Response updateVIP( @PathParam("containerName") String containerName, @TypeHint(VIP.class) VIP inVIP) { VIP vipInput = inVIP; String name = vipInput.getName(); String poolName = vipInput.getPoolName(); if (name.isEmpty() || poolName.isEmpty()) { throw new UnsupportedMediaTypeException(RestMessages.INVALIDDATA.toString()); } IConfigManager configManager = getConfigManagerService(containerName); if (configManager == null) { throw new ServiceUnavailableException( "Load Balancer " + RestMessages.SERVICEUNAVAILABLE.toString()); } if (!configManager.poolExists(poolName)) throw new ResourceNotFoundException(NBConst.RES_POOL_NOT_FOUND); if (configManager.getVIPAttachedPool(name) != null) throw new MethodNotAllowedException(NBConst.RES_VIP_POOL_EXIST); if (configManager.updateVIP(name, poolName) != null) return Response.status(Response.Status.ACCEPTED).build(); throw new InternalServerErrorException(NBConst.RES_VIP_UPDATE_FAILED); }
@Path("/{containerName}/create/vip") @POST @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @StatusCodes({ @ResponseCode(code = 201, condition = "VIP created successfully"), @ResponseCode(code = 404, condition = "The Container Name not found"), @ResponseCode(code = 503, condition = "Load balancer service is unavailable"), @ResponseCode(code = 409, condition = "VIP already exist"), @ResponseCode(code = 415, condition = "Invalid input data") }) public Response addVIP( @PathParam("containerName") String containerName, @TypeHint(VIP.class) VIP inVIP) { VIP vipInput = inVIP; String name = vipInput.getName(); String ip = vipInput.getIp(); String protocol = vipInput.getProtocol(); short protocolPort = vipInput.getPort(); String poolName = vipInput.getPoolName(); if (name.isEmpty() || ip.isEmpty() || protocol.isEmpty() || protocolPort < 0) { throw new UnsupportedMediaTypeException(RestMessages.INVALIDDATA.toString()); } IConfigManager configManager = getConfigManagerService(containerName); if (configManager == null) { throw new ServiceUnavailableException( "Load Balancer " + RestMessages.SERVICEUNAVAILABLE.toString()); } if (!configManager.vipExists(name, ip, protocol, protocolPort, poolName)) { VIP vip = configManager.createVIP(name, ip, protocol, protocolPort, poolName); if (vip != null) { return Response.status(Response.Status.CREATED).build(); } } else { throw new ResourceConflictException(NBConst.RES_VIP_ALREADY_EXIST); } throw new InternalServerErrorException(NBConst.RES_VIP_CREATION_FAILED); }