Class TargetController
- java.lang.Object
-
- org.craftercms.deployer.impl.rest.TargetController
-
@RestController @RequestMapping("/api/1/target") public class TargetController extends Object
Main controller for target related operations.- Author:
- avasquez
-
-
Field Summary
Fields Modifier and Type Field Description static String
BASE_URL
static String
CREATE_TARGET_IF_NOT_EXISTS_URL
static String
CREATE_TARGET_URL
static String
DELETE_IF_EXIST_TARGET_URL
static String
DELETE_TARGET_URL
static String
DEPLOY_ALL_TARGETS_URL
static String
DEPLOY_TARGET_URL
protected DeploymentService
deploymentService
static String
GET_ALL_DEPLOYMENTS_URL
static String
GET_ALL_TARGETS_URL
static String
GET_CURRENT_DEPLOYMENT_URL
static String
GET_PENDING_DEPLOYMENTS_URL
static String
GET_TARGET_URL
protected String
managementToken
static String
RECREATE_INDEX_URL
static String
REPLACE_PARAM_NAME
static String
SEARCH_ENGINE_PARAM_NAME
static String
SEARCH_ENGINE_PARAM_VALUE
protected TargetService
targetService
static String
TEMPLATE_NAME_PARAM_NAME
static String
UNLOCK_TARGET_URL
static String
USE_CRAFTER_SEARCH_PARAM_NAME
-
Constructor Summary
Constructors Constructor Description TargetController(TargetService targetService, DeploymentService deploymentService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.springframework.http.HttpHeaders
createResponseHeaders(String locationUrlTemplate, Object... variables)
org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result>
createTarget(Map<String,Object> params)
Creates a DeployerTarget
.protected org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result>
createTarget(Map<String,Object> params, boolean createIfNotExists)
org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result>
createTargetIfNotExists(Map<String,Object> params)
org.springframework.http.ResponseEntity<Void>
deleteTarget(String env, String siteName)
Deletes theTarget
with the specified environment and site name.org.springframework.http.ResponseEntity<Void>
deleteTargetIfExists(String env, String siteName)
Deletes theTarget
with the specified environment and site name, does nothing if the target is not found.org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result>
deployAllTargets(Map<String,Object> params)
Deploys all currentTarget
s.org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result>
deployTarget(String env, String siteName, Map<String,Object> params)
Deploys theTarget
with the specified environment and site name.org.springframework.http.ResponseEntity<Collection<Deployment>>
getAllDeployments(String env, String siteName)
Gets all deployments for a target (pending and current).org.springframework.http.ResponseEntity<List<Target>>
getAllTargets()
Returns all currentTarget
sorg.springframework.http.ResponseEntity<Deployment>
getCurrentDeployment(String env, String siteName)
Gets the current deployment for a target.org.springframework.http.ResponseEntity<Collection<Deployment>>
getPendingDeployments(String env, String siteName)
Gets the pending deployments for a target.org.springframework.http.ResponseEntity<Target>
getTarget(String env, String siteName)
Returns aTarget
.org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result>
recreateIndex(String env, String siteName, String token)
Recreates the underlying Elasticsearch index for theTarget
with the specified environment and site name.void
unlockTarget(String env, String siteName, String token)
protected void
validateToken(String token)
-
-
-
Field Detail
-
BASE_URL
public static final String BASE_URL
- See Also:
- Constant Field Values
-
CREATE_TARGET_URL
public static final String CREATE_TARGET_URL
- See Also:
- Constant Field Values
-
CREATE_TARGET_IF_NOT_EXISTS_URL
public static final String CREATE_TARGET_IF_NOT_EXISTS_URL
- See Also:
- Constant Field Values
-
GET_TARGET_URL
public static final String GET_TARGET_URL
- See Also:
- Constant Field Values
-
GET_ALL_TARGETS_URL
public static final String GET_ALL_TARGETS_URL
- See Also:
- Constant Field Values
-
DELETE_TARGET_URL
public static final String DELETE_TARGET_URL
- See Also:
- Constant Field Values
-
DELETE_IF_EXIST_TARGET_URL
public static final String DELETE_IF_EXIST_TARGET_URL
- See Also:
- Constant Field Values
-
DEPLOY_TARGET_URL
public static final String DEPLOY_TARGET_URL
- See Also:
- Constant Field Values
-
DEPLOY_ALL_TARGETS_URL
public static final String DEPLOY_ALL_TARGETS_URL
- See Also:
- Constant Field Values
-
GET_PENDING_DEPLOYMENTS_URL
public static final String GET_PENDING_DEPLOYMENTS_URL
- See Also:
- Constant Field Values
-
GET_CURRENT_DEPLOYMENT_URL
public static final String GET_CURRENT_DEPLOYMENT_URL
- See Also:
- Constant Field Values
-
GET_ALL_DEPLOYMENTS_URL
public static final String GET_ALL_DEPLOYMENTS_URL
- See Also:
- Constant Field Values
-
UNLOCK_TARGET_URL
public static final String UNLOCK_TARGET_URL
- See Also:
- Constant Field Values
-
RECREATE_INDEX_URL
public static final String RECREATE_INDEX_URL
- See Also:
- Constant Field Values
-
REPLACE_PARAM_NAME
public static final String REPLACE_PARAM_NAME
- See Also:
- Constant Field Values
-
TEMPLATE_NAME_PARAM_NAME
public static final String TEMPLATE_NAME_PARAM_NAME
- See Also:
- Constant Field Values
-
SEARCH_ENGINE_PARAM_NAME
public static final String SEARCH_ENGINE_PARAM_NAME
- See Also:
- Constant Field Values
-
SEARCH_ENGINE_PARAM_VALUE
public static final String SEARCH_ENGINE_PARAM_VALUE
- See Also:
- Constant Field Values
-
USE_CRAFTER_SEARCH_PARAM_NAME
public static final String USE_CRAFTER_SEARCH_PARAM_NAME
- See Also:
- Constant Field Values
-
targetService
protected TargetService targetService
-
deploymentService
protected DeploymentService deploymentService
-
managementToken
@Value("${deployer.main.management.authorizationToken}") protected String managementToken
-
-
Constructor Detail
-
TargetController
@Autowired public TargetController(TargetService targetService, DeploymentService deploymentService)
-
-
Method Detail
-
createTarget
@RequestMapping(value="/create", method=POST) public org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result> createTarget(@RequestBody Map<String,Object> params) throws DeployerException, org.craftercms.commons.validation.ValidationException
Creates a DeployerTarget
.- Parameters:
params
- the body of the request with the template parameters that will be used to create the target. The body must contain at least aenv
andsite_name
parameter. Other required parameters depend on the template used.- Returns:
- the response entity 201 CREATED status
- Throws:
DeployerException
- if an error occurred during target creationorg.craftercms.commons.validation.ValidationException
- if a required parameter is missing
-
createTargetIfNotExists
@RequestMapping(value="/create_if_not_exists", method=POST) public org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result> createTargetIfNotExists(@RequestBody Map<String,Object> params) throws DeployerException, org.craftercms.commons.validation.ValidationException
- Throws:
DeployerException
org.craftercms.commons.validation.ValidationException
-
getTarget
@RequestMapping(value="/get/{env}/{site_name}", method=GET) public org.springframework.http.ResponseEntity<Target> getTarget(@PathVariable("env") String env, @PathVariable("site_name") String siteName) throws DeployerException
Returns aTarget
.- Parameters:
env
- the target's environmentsiteName
- the target's site name- Returns:
- the response entity with the target's properties and 200 OK status
- Throws:
DeployerException
- if an error occurred
-
getAllTargets
@RequestMapping(value="/get-all", method=GET) public org.springframework.http.ResponseEntity<List<Target>> getAllTargets() throws DeployerException
Returns all currentTarget
s- Returns:
- the response entity with all the properties of the targets and 200 OK status
- Throws:
DeployerException
- if an error occurred
-
deleteTarget
@RequestMapping(value="/delete/{env}/{site_name}", method=POST) public org.springframework.http.ResponseEntity<Void> deleteTarget(@PathVariable("env") String env, @PathVariable("site_name") String siteName) throws DeployerException
Deletes theTarget
with the specified environment and site name.- Parameters:
env
- the target's environmentsiteName
- the target's site name- Returns:
- the response entity with a 204 NO CONTENT status
- Throws:
DeployerException
- if an error occurred
-
deleteTargetIfExists
@RequestMapping(value="/delete-if-exists/{env}/{site_name}", method=POST) public org.springframework.http.ResponseEntity<Void> deleteTargetIfExists(@PathVariable("env") String env, @PathVariable("site_name") String siteName) throws DeployerException
Deletes theTarget
with the specified environment and site name, does nothing if the target is not found.- Parameters:
env
- the target's environmentsiteName
- the target's site name- Returns:
- the response entity with a 204 NO CONTENT status
- Throws:
DeployerException
- if an error occurred
-
deployTarget
@RequestMapping(value="/deploy/{env}/{site_name}", method=POST) public org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result> deployTarget(@PathVariable("env") String env, @PathVariable("site_name") String siteName, @RequestBody(required=false) Map<String,Object> params) throws DeployerException
Deploys theTarget
with the specified environment and site name.- Parameters:
env
- the target's environmentsiteName
- the target's site nameparams
- any additional parameters that can be used by theDeploymentProcessor
s, for examplereprocess_all_files
- Returns:
- the response entity with a 200 OK status
- Throws:
DeployerException
- if an error occurred
-
deployAllTargets
@RequestMapping(value="/deploy-all", method=POST) public org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result> deployAllTargets(@RequestBody(required=false) Map<String,Object> params) throws DeployerException
Deploys all currentTarget
s.- Parameters:
params
- any additional parameters that can be used by theDeploymentProcessor
s, for examplereprocess_all_files
- Returns:
- the response entity with a 200 OK status
- Throws:
DeployerException
- if an error occurred
-
getPendingDeployments
@RequestMapping(value="/deployments/get-pending/{env}/{site_name}", method=GET) public org.springframework.http.ResponseEntity<Collection<Deployment>> getPendingDeployments(@PathVariable("env") String env, @PathVariable("site_name") String siteName) throws DeployerException
Gets the pending deployments for a target.- Parameters:
env
- the target's environmentsiteName
- the target's site name- Returns:
- the pending deployments for the target
- Throws:
DeployerException
- if an error occurred
-
getCurrentDeployment
@RequestMapping(value="/deployments/get-current/{env}/{site_name}", method=GET) public org.springframework.http.ResponseEntity<Deployment> getCurrentDeployment(@PathVariable("env") String env, @PathVariable("site_name") String siteName) throws DeployerException
Gets the current deployment for a target.- Parameters:
env
- the target's environmentsiteName
- the target's site name- Returns:
- the pending and current deployments for the target
- Throws:
DeployerException
- if an error occurred
-
getAllDeployments
@RequestMapping(value="/deployments/get-all/{env}/{site_name}", method=GET) public org.springframework.http.ResponseEntity<Collection<Deployment>> getAllDeployments(@PathVariable("env") String env, @PathVariable("site_name") String siteName) throws DeployerException
Gets all deployments for a target (pending and current).- Parameters:
env
- the target's environmentsiteName
- the target's site name- Returns:
- the pending and current deployments for the target
- Throws:
DeployerException
- if an error occurred
-
recreateIndex
@RequestMapping(value="/recreate/{env}/{site_name}", method=POST) public org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result> recreateIndex(@PathVariable("env") String env, @PathVariable("site_name") String siteName, @RequestParam String token) throws DeployerException, org.craftercms.commons.exceptions.InvalidManagementTokenException
Recreates the underlying Elasticsearch index for theTarget
with the specified environment and site name.- Parameters:
env
- the target's environmentsiteName
- the target's site name- Returns:
- the response entity with a 200 OK status
- Throws:
DeployerException
- if an error occurredorg.craftercms.commons.exceptions.InvalidManagementTokenException
-
createTarget
protected org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result> createTarget(Map<String,Object> params, boolean createIfNotExists) throws org.craftercms.commons.validation.ValidationException, DeployerException
- Throws:
org.craftercms.commons.validation.ValidationException
DeployerException
-
createResponseHeaders
protected org.springframework.http.HttpHeaders createResponseHeaders(String locationUrlTemplate, Object... variables)
-
unlockTarget
@ResponseStatus(OK) @PostMapping("/unlock/{env}/{site_name}") public void unlockTarget(@PathVariable("env") String env, @PathVariable("site_name") String siteName, @RequestParam String token) throws TargetNotFoundException, TargetServiceException, org.craftercms.commons.exceptions.InvalidManagementTokenException
- Throws:
TargetNotFoundException
TargetServiceException
org.craftercms.commons.exceptions.InvalidManagementTokenException
-
validateToken
protected void validateToken(String token) throws org.craftercms.commons.exceptions.InvalidManagementTokenException
- Throws:
org.craftercms.commons.exceptions.InvalidManagementTokenException
-
-