Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.emitrom.integra.core.configuration.Providers
- import com.emitrom.integra.core.configuration.Schedules
- import com.emitrom.integra.core.configuration.WorkflowActions
- import com.emitrom.integra.core.configuration.Workflows
- import com.emitrom.integra.core.schedules.ScheduleResults
- import javax.ws.rs.client.Client
- import javax.ws.rs.client.ClientBuilder
- import javax.ws.rs.client.WebTarget
- class IntegraClean {
- public static void main(args) {
- def cli = new CliBuilder(usage: 'IntegraClean [options]')
- cli.u(longOpt: 'url', args: 1, argName: 'restURL', 'Integra REST URL', required: true)
- def options = cli.parse(args)
- // make sure we got stuff
- assert options
- String baseUrl = options.url
- // tack on a trailing slash if the input doesn't provide one
- if (!baseUrl.endsWith('/')) {
- baseUrl += '/'
- }
- Authenticator myAuth = new Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("admin", "integra".toCharArray());
- }
- };
- Authenticator.setDefault(myAuth);
- Client client = ClientBuilder.newClient()
- WebTarget target = client.target(baseUrl)
- deleteSchedules(target)
- deleteWorkflows(target)
- deleteWorkflowActions(target)
- deleteProviders(target)
- deleteScheduleResults(target)
- }
- private static void deleteSchedules(WebTarget target) {
- println "\nDeleting schedules..."
- def schedulesPath = 'schedules/'
- Schedules schedules = target.path(schedulesPath).request().get(Schedules.class)
- int schedulesDeleted = 0
- schedules?.getSchedule().each() { schedule ->
- target.path(schedulesPath + schedule.id).request().delete()
- println 'Deleted ' + schedule.name
- schedulesDeleted++
- }
- println 'Schedules deleted: ' + schedulesDeleted
- }
- private static void deleteWorkflows(WebTarget target) {
- println "\nDeleting workflows..."
- def workflowsPath = 'workflows/'
- Workflows workflows = target.path(workflowsPath).request().get(Workflows.class)
- int workflowsDeleted = 0
- workflows?.getWorkflow().each() { workflow ->
- target.path(workflowsPath + workflow.id).request().delete()
- println 'Deleted ' + workflow.name
- workflowsDeleted++
- }
- println 'Workflows deleted: ' + workflowsDeleted
- }
- private static void deleteWorkflowActions(WebTarget target) {
- println "\nDeleting actions..."
- def workflowActionsPath = 'workflow_actions/'
- WorkflowActions workflowActions = target.path(workflowActionsPath).request().get(WorkflowActions.class)
- int actionsDeleted = 0
- workflowActions?.workflowAction?.each() { action ->
- target.path(workflowActionsPath + action.id).request().delete()
- println 'Deleted ' + action.name
- actionsDeleted++
- }
- println 'Actions deleted: ' + actionsDeleted
- }
- private static void deleteProviders(WebTarget target) {
- println "\nDeleting providers..."
- def providersPath = 'providers/'
- Providers providers = target.path(providersPath).request().get(Providers.class)
- int providersDeleted = 0
- providers?.getProvider().each() { provider ->
- target.path(providersPath + provider.id).request().delete()
- println 'Deleted ' + provider.name
- providersDeleted++
- }
- println 'Providers deleted: ' + providersDeleted
- }
- private static void deleteScheduleResults(WebTarget target) {
- println "\nDeleting schedule results..."
- def scheduleResultsPath = 'schedules_results/'
- ScheduleResults scheduleResults = target.path(scheduleResultsPath).request().get(ScheduleResults.class)
- int schedulesDeleted = 0
- scheduleResults?.getScheduleResults().each() { scheduleResult ->
- target.path(scheduleResultsPath + scheduleResult.id).request().delete()
- println 'Deleted ' + scheduleResult.id
- schedulesDeleted++
- }
- println 'Schedule results deleted: ' + schedulesDeleted
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement