Add Admin task for UAT to kick off cleanup of models

- Fixes #163
This commit is contained in:
Giri Dandu 2015-05-05 17:24:37 -04:00
parent b7366a00dd
commit c75b53510b
2 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,16 @@
Feature: DeployDB cleanup APIs
As a DeployDB administrator
I should be able to cleanup the artifact, deployment promotion results models
@dbd
Scenario: The model cleanup shall be successful
Given there is a deployment
When I POST to "/tasks/modelCleanup?group=com.example.cucumber&name=cucumber-artifact&version=1.0.1" from the admin app
Then the response should be 200
And the response body should be:
"""
Done!
"""
And the artifact doesn't exist

View File

@ -0,0 +1,45 @@
package deploydb
import com.codahale.metrics.annotation.Timed
import com.google.common.collect.ImmutableMultimap
import io.dropwizard.servlets.tasks.Task
import org.slf4j.Logger
import org.slf4j.LoggerFactory
/**
* Admin task to Cleanup models in the deploydb
*/
class ModelCleanupTask extends Task {
private WorkFlow workFlow
private static final Logger logger = LoggerFactory.getLogger(ConfigReloadTask.class)
/**
* Constructor
*
* @param workFlow - store the workFlow for executing load config
*/
ModelCleanupTask(WorkFlow workFlow) {
super('modelCleanup')
this.workFlow = workFlow
}
@Timed
@Override
void execute(ImmutableMultimap<String, String> parameters, PrintWriter output) throws Exception {
String group = String.valueOf(parameters.get("group").toArray()[0])
String name = String.valueOf(parameters.get("name").toArray()[0])
String version = String.valueOf(parameters.get("version").toArray()[0])
this.workFlow.deployDBApp.withHibernateSession() {
try {
this.workFlow.flowDAO.deleteFlowByArtifactNameGroupVersion(group, name, version)
output.println("Done!")
} catch (Exception e) {
logger.error("Cleanup of the model failed with an exception: ", e)
output.println("Failed: " + e.getMessage())
throw e
}
}
}
}