Class TargetController
- java.lang.Object
-
- org.craftercms.deployer.impl.rest.TargetController
-
@Validated @RestController @RequestMapping("/api/1/target") public class TargetController extends Object
Main controller for target related operations.- Author:
- avasquez
-
-
Field Summary
-
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(@Valid CreateTargetRequest params)
Creates a DeployerTarget
.protected org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result>
createTarget(CreateTargetRequest createRequest, boolean createIfNotExists)
org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result>
createTargetIfNotExists(@Valid CreateTargetRequest params)
org.springframework.http.ResponseEntity<Void>
deleteTarget(@NotBlank String env, @NotBlank String siteName)
Deletes theTarget
with the specified environment and site name.org.springframework.http.ResponseEntity<Void>
deleteTargetIfExists(@NotBlank String env, @NotBlank 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(@NotBlank String env, @NotBlank String siteName, Map<String,Object> params)
Deploys theTarget
with the specified environment and site name.org.springframework.http.ResponseEntity<Collection<Deployment>>
getAllDeployments(@NotBlank String env, @NotBlank 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(@NotBlank String env, @NotBlank String siteName)
Gets the current deployment for a target.org.springframework.http.ResponseEntity<Collection<Deployment>>
getPendingDeployments(@NotBlank String env, @NotBlank String siteName)
Gets the pending deployments for a target.org.springframework.http.ResponseEntity<Target>
getTarget(@NotBlank String env, @NotBlank String siteName)
Returns aTarget
.org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result>
recreateIndex(@NotBlank String env, @NotBlank 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
-
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
-
REPO_URL_PARAM_NAME
public static final String REPO_URL_PARAM_NAME
- See Also:
- Constant Field Values
-
REPO_BRANCH_PARAM_NAME
public static final String REPO_BRANCH_PARAM_NAME
- See Also:
- Constant Field Values
-
REPO_USERNAME_PARAM_NAME
public static final String REPO_USERNAME_PARAM_NAME
- See Also:
- Constant Field Values
-
SSH_PRIVATE_KEY_PATH_PARAM_NAME
public static final String SSH_PRIVATE_KEY_PATH_PARAM_NAME
- See Also:
- Constant Field Values
-
ENGINE_URL_PARAM_NAME
public static final String ENGINE_URL_PARAM_NAME
- See Also:
- Constant Field Values
-
NOTIFICATION_ADDRESSESS_PARAM_NAME
public static final String NOTIFICATION_ADDRESSESS_PARAM_NAME
- See Also:
- Constant Field Values
-
targetService
protected final TargetService targetService
-
deploymentService
protected final 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(@Valid @RequestBody @Valid CreateTargetRequest params) throws DeployerException
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 creation
-
createTargetIfNotExists
@RequestMapping(value="/create_if_not_exists", method=POST) public org.springframework.http.ResponseEntity<org.craftercms.commons.rest.Result> createTargetIfNotExists(@Valid @RequestBody @Valid CreateTargetRequest params) throws DeployerException
- Throws:
DeployerException
-
getTarget
@RequestMapping(value="/get/{env}/{site_name}", method=GET) public org.springframework.http.ResponseEntity<Target> getTarget(@NotBlank @PathVariable("env") @NotBlank String env, @NotBlank @PathVariable("site_name") @NotBlank 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(@NotBlank @PathVariable("env") @NotBlank String env, @NotBlank @PathVariable("site_name") @NotBlank 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(@NotBlank @PathVariable("env") @NotBlank String env, @NotBlank @PathVariable("site_name") @NotBlank 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(@NotBlank @PathVariable("env") @NotBlank String env, @NotBlank @PathVariable("site_name") @NotBlank 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(@NotBlank @PathVariable("env") @NotBlank String env, @NotBlank @PathVariable("site_name") @NotBlank 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(@NotBlank @PathVariable("env") @NotBlank String env, @NotBlank @PathVariable("site_name") @NotBlank 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(@NotBlank @PathVariable("env") @NotBlank String env, @NotBlank @PathVariable("site_name") @NotBlank 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(@NotBlank @PathVariable("env") @NotBlank String env, @NotBlank @PathVariable("site_name") @NotBlank 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(CreateTargetRequest createRequest, boolean createIfNotExists) throws DeployerException
- Throws:
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
-
-