Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1120418] Starting pseudo-code for executing a job.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Negrea committed Jul 31, 2014
1 parent 7a277ae commit 9891be2
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
@@ -0,0 +1,65 @@
/*
* RHQ Management Platform
* Copyright (C) 2005-2014 Red Hat, Inc.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.rhq.enterprise.server.storage.maintenance.job;

import java.util.HashMap;
import java.util.Map;

import javax.ejb.EJB;

import org.rhq.core.domain.storage.MaintenanceJob;
import org.rhq.core.domain.storage.MaintenanceStep;
import org.rhq.enterprise.server.storage.maintenance.step.MaintenanceStepRunner;
import org.rhq.enterprise.server.storage.maintenance.step.ShutdownStorageClient;
import org.rhq.enterprise.server.storage.maintenance.step.StartStorageClient;
import org.rhq.enterprise.server.storage.maintenance.step.UpdateStorageNodeEndpoints;
import org.rhq.enterprise.server.storage.maintenance.step.UpdateStorageNodeEntity;

public class MaintenanceJobRunner {

@EJB
StartStorageClient startStorageClient;

@EJB
ShutdownStorageClient shutdownStorageClient;

@EJB
UpdateStorageNodeEndpoints updateStorageNodeEndpoints;

@EJB
UpdateStorageNodeEntity updateStorageNodeEntity;


public void runJob(MaintenanceJob job) {
Map<String, MaintenanceStepRunner> runners = new HashMap<String, MaintenanceStepRunner>();
runners.put(startStorageClient.getClass().getSimpleName(), startStorageClient);
runners.put(shutdownStorageClient.getClass().getSimpleName(), shutdownStorageClient);
runners.put(updateStorageNodeEndpoints.getClass().getSimpleName(), updateStorageNodeEndpoints);
runners.put(updateStorageNodeEntity.getClass().getSimpleName(), updateStorageNodeEntity);


for (MaintenanceStep step : job.getMaintenanceSteps()) {
try {
runners.get(step.getOperationName()).execute(step);
} catch (Exception e) {
//do nothing for now ... exception handling to be decided a later
}
}
}
}
Expand Up @@ -19,15 +19,16 @@
package org.rhq.enterprise.server.storage.maintenance.step;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.rhq.core.domain.storage.MaintenanceJob;
import org.rhq.core.domain.storage.MaintenanceStep;
import org.rhq.enterprise.server.storage.StorageClientManager;

/**
* @author Stefan Negrea
*
*/
@Stateless
public class ShutdownStorageClient implements MaintenanceStepRunner {

@EJB
Expand All @@ -37,15 +38,4 @@ public class ShutdownStorageClient implements MaintenanceStepRunner {
public void execute(MaintenanceStep maintenanceStep) {
storageClientManager.shutdown();
}

@Override
public MaintenanceStep build(MaintenanceJob job, int stepNumber, String[] existingNodes, String affectedNode) {
MaintenanceStep step = new MaintenanceStep();

step.setStep(stepNumber)
.setName(ShutdownStorageClient.class.getSimpleName())
.setMaintenanceJob(job);

return step;
}
}
Expand Up @@ -19,6 +19,7 @@
package org.rhq.enterprise.server.storage.maintenance.step;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.rhq.core.domain.storage.MaintenanceStep;
import org.rhq.enterprise.server.storage.StorageClientManager;
Expand All @@ -27,6 +28,7 @@
* @author Stefan Negrea
*
*/
@Stateless
public class StartStorageClient implements MaintenanceStepRunner {

@EJB
Expand Down
Expand Up @@ -19,6 +19,7 @@
package org.rhq.enterprise.server.storage.maintenance.step;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.rhq.core.domain.cloud.StorageNode;
import org.rhq.core.domain.common.JobTrigger;
Expand All @@ -39,6 +40,7 @@
* @author Stefan Negrea
*
*/
@Stateless
public class UpdateStorageNodeEndpoints implements MaintenanceStepRunner {

@EJB
Expand Down
Expand Up @@ -19,6 +19,7 @@
package org.rhq.enterprise.server.storage.maintenance.step;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

Expand All @@ -31,6 +32,7 @@
* @author Stefan Negrea
*
*/
@Stateless
public class UpdateStorageNodeEntity implements MaintenanceStepRunner {

@EJB
Expand Down

0 comments on commit 9891be2

Please sign in to comment.