Skip to content

Commit

Permalink
tech : code climate fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Radislav Berkovich committed Apr 28, 2019
1 parent 2af4a50 commit c4b8eac
Showing 1 changed file with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@

import com.hp.octane.integrations.dto.pipelines.PipelinePhase;
import com.microfocus.application.automation.tools.octane.executor.UftConstants;
import com.microfocus.application.automation.tools.octane.model.processors.builders.*;
import com.microfocus.application.automation.tools.octane.model.processors.builders.AbstractBuilderProcessor;
import com.microfocus.application.automation.tools.octane.model.processors.builders.BuildTriggerProcessor;
import com.microfocus.application.automation.tools.octane.model.processors.builders.ParameterizedTriggerProcessor;
import com.microfocus.application.automation.tools.octane.tests.build.BuildHandlerUtils;
import hudson.model.*;
import hudson.tasks.Builder;
Expand Down Expand Up @@ -78,42 +80,53 @@ public void scheduleBuild(Cause cause, ParametersAction parametersAction) {
}

public void cancelBuild(Cause cause, ParametersAction parametersAction) {
String suiteId = (String) parametersAction.getParameter(UftConstants.SUITE_ID_PARAMETER_NAME).getValue();
String suiteRunId = (String) parametersAction.getParameter(UftConstants.SUITE_RUN_ID_PARAMETER_NAME).getValue();
logger.info("cancelBuild for suiteId=" + suiteId +", suiteRunId=" + suiteRunId);
if (job instanceof AbstractProject) {
AbstractProject project = (AbstractProject) job;
Queue queue = Jenkins.get().getQueue();
queue.getItems(project).forEach(item -> {
item.getActions(ParametersAction.class).forEach(action -> {
if (action.getParameter(UftConstants.SUITE_ID_PARAMETER_NAME).getValue().equals(parametersAction.getParameter(UftConstants.SUITE_ID_PARAMETER_NAME).getValue())
&& action.getParameter(UftConstants.SUITE_RUN_ID_PARAMETER_NAME).getValue().equals(parametersAction.getParameter(UftConstants.SUITE_RUN_ID_PARAMETER_NAME).getValue())) {
if (checkSuiteIdParamsExistAndEqual(action, suiteId, suiteRunId)) {
try {
logger.info("canceling item in queue : " + item.getDisplayName());
queue.cancel(item);
} catch (Exception e) {
logger.warn(e);
logger.warn("Failed to cancel '" + item.getDisplayName() + "' in queue : " + e.getMessage(), e);
}
}
});
});

project.getBuilds().forEach(build -> {
if (build instanceof AbstractBuild) {
AbstractBuild abuild = (AbstractBuild) build;
abuild.getActions(ParametersAction.class).forEach(action -> {
if (action.getParameter(UftConstants.SUITE_ID_PARAMETER_NAME).getValue().equals(parametersAction.getParameter(UftConstants.SUITE_ID_PARAMETER_NAME).getValue())
&& action.getParameter(UftConstants.SUITE_RUN_ID_PARAMETER_NAME).getValue().equals(parametersAction.getParameter(UftConstants.SUITE_RUN_ID_PARAMETER_NAME).getValue())) {
try {
abuild.doStop();
} catch (Exception e) {
logger.warn(e);
AbstractBuild aBuild = (AbstractBuild) build;
if(aBuild.isBuilding()) {
aBuild.getActions(ParametersAction.class).forEach(action -> {
if (checkSuiteIdParamsExistAndEqual(action, suiteId, suiteRunId)) {
try {
aBuild.doStop();
} catch (Exception e) {
logger.warn("Failed to stop build '" + aBuild.getDisplayName() + "' :" + e.getMessage(), e);
}
}
}
});
});
}
}
});
} else {
throw new IllegalStateException("unsupported job CAN NOT be stop");
throw new IllegalStateException("unsupported job CAN NOT be stopped");
}
}

private boolean checkSuiteIdParamsExistAndEqual(ParametersAction parametersAction, String suiteId, String suiteRunId) {
ParameterValue suiteIdPV = parametersAction.getParameter(UftConstants.SUITE_ID_PARAMETER_NAME);
ParameterValue suiteRunIdPV = parametersAction.getParameter(UftConstants.SUITE_RUN_ID_PARAMETER_NAME);
return (suiteIdPV != null && suiteRunIdPV != null && suiteIdPV.getValue().equals(suiteId)
&& suiteRunIdPV.getValue().equals(suiteRunId));
}

/**
* Retrieve Job's CI ID
* return the job name, in case of a folder job, this method returns the refactored
Expand Down

0 comments on commit c4b8eac

Please sign in to comment.