use of io.mantisrx.server.master.domain.JobClusterDefinitionImpl in project mantis by Netflix.
the class JobDefinitionResolverTest method artifactPresentButSchedAbsentFailsTest.
@Test
public void artifactPresentButSchedAbsentFailsTest() {
String clusterName = "artifactPresentButSchedAbsentFailsTest";
List<Label> labels = new ArrayList<>();
Label label = new Label("l1", "lv1");
labels.add(label);
List<Parameter> parameters = new ArrayList<>();
Parameter parameter = new Parameter("paramName", "paramValue");
parameters.add(parameter);
final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, labels, parameters);
IJobClusterMetadata jobClusterMetadata = new JobClusterMetadataImpl(fakeJobCluster, 1, false);
String version = "0.0.2";
String artifactName = "myArt2";
// Only new artifact and version is specified
try {
JobDefinition givenJobDefn = new JobDefinition.Builder().withArtifactName(artifactName).withName(clusterName).withVersion(version).build();
JobDefinitionResolver resolver = new JobDefinitionResolver();
JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
fail();
} catch (Exception e) {
e.printStackTrace();
}
// Only new artifact is specified
try {
JobDefinition givenJobDefn = new JobDefinition.Builder().withArtifactName(artifactName).withName(clusterName).build();
JobDefinitionResolver resolver = new JobDefinitionResolver();
JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
fail();
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.mantisrx.server.master.domain.JobClusterDefinitionImpl in project mantis by Netflix.
the class JobDefinitionResolverTest method versionNotFoundTest.
@Test
public void versionNotFoundTest() {
String clusterName = "versionNotFoundTest";
List<Label> labels = new ArrayList<>();
Label label = new Label("l1", "lv1");
labels.add(label);
List<Parameter> parameters = new ArrayList<>();
Parameter parameter = new Parameter("paramName", "paramValue");
parameters.add(parameter);
final JobClusterDefinitionImpl fakeJobCluster = createFakeJobClusterDefn(clusterName, labels, parameters);
IJobClusterMetadata jobClusterMetadata = new JobClusterMetadataImpl(fakeJobCluster, 1, false);
String version = "0.0.2";
try {
JobDefinition givenJobDefn = new JobDefinition.Builder().withName(clusterName).withVersion(version).build();
JobDefinitionResolver resolver = new JobDefinitionResolver();
JobDefinition resolvedJobDefinition = resolver.getResolvedJobDefinition("user", givenJobDefn, jobClusterMetadata);
fail();
} catch (Exception e) {
e.printStackTrace();
}
}
use of io.mantisrx.server.master.domain.JobClusterDefinitionImpl in project mantis by Netflix.
the class JobClusterActor method onJobClusterUpdateLabels.
@Override
public void onJobClusterUpdateLabels(UpdateJobClusterLabelsRequest labelRequest) {
if (logger.isTraceEnabled()) {
logger.trace("Enter onJobClusterUpdateLabels {}", labelRequest);
}
ActorRef sender = getSender();
try {
JobClusterConfig newConfig = new JobClusterConfig.Builder().from(jobClusterMetadata.getJobClusterDefinition().getJobClusterConfig()).build();
JobClusterDefinitionImpl updatedDefn = new JobClusterDefinitionImpl.Builder().from(jobClusterMetadata.getJobClusterDefinition()).withJobClusterConfig(newConfig).withLabels(labelRequest.getLabels()).build();
IJobClusterMetadata jobCluster = new JobClusterMetadataImpl.Builder().withIsDisabled(jobClusterMetadata.isDisabled()).withLastJobCount(jobClusterMetadata.getLastJobCount()).withJobClusterDefinition(updatedDefn).build();
updateAndSaveJobCluster(jobCluster);
sender.tell(new UpdateJobClusterLabelsResponse(labelRequest.requestId, SUCCESS, name + " labels updated"), getSelf());
eventPublisher.publishAuditEvent(new LifecycleEventsProto.AuditEvent(LifecycleEventsProto.AuditEvent.AuditEventType.JOB_CLUSTER_UPDATE, jobClusterMetadata.getJobClusterDefinition().getName(), name + " update labels"));
} catch (Exception e) {
logger.error("job cluster labels not updated ", e);
sender.tell(new UpdateJobClusterLabelsResponse(labelRequest.requestId, SERVER_ERROR, name + " labels updation failed " + e.getMessage()), getSelf());
}
if (logger.isTraceEnabled()) {
logger.trace("Exit onJobClusterUpdateLabels {}", labelRequest);
}
}
use of io.mantisrx.server.master.domain.JobClusterDefinitionImpl in project mantis by Netflix.
the class JobClusterActor method onJobClusterEnable.
@Override
public void onJobClusterEnable(final EnableJobClusterRequest req) {
if (logger.isTraceEnabled()) {
logger.trace("Enter onJobClusterEnable");
}
ActorRef sender = getSender();
try {
IJobClusterMetadata jobClusterMetadata = new JobClusterMetadataImpl.Builder().withIsDisabled(false).withLastJobCount(this.jobClusterMetadata.getLastJobCount()).withJobClusterDefinition((JobClusterDefinitionImpl) this.jobClusterMetadata.getJobClusterDefinition()).build();
// update store
jobStore.updateJobCluster(jobClusterMetadata);
this.jobClusterMetadata = jobClusterMetadata;
if (cronManager == null) {
cronManager = new CronManager(name, getSelf(), jobClusterMetadata.getJobClusterDefinition().getSLA());
}
this.cronManager.initCron();
// change behavior to enabled
getContext().become(initializedBehavior);
// start SLA timer
setBookkeepingTimer(BOOKKEEPING_INTERVAL_SECS);
eventPublisher.publishAuditEvent(new LifecycleEventsProto.AuditEvent(LifecycleEventsProto.AuditEvent.AuditEventType.JOB_CLUSTER_ENABLED, this.jobClusterMetadata.getJobClusterDefinition().getName(), name + " enabled"));
sender.tell(new EnableJobClusterResponse(req.requestId, SUCCESS, String.format("%s enabled", name)), getSelf());
numJobClusterEnable.increment();
logger.info("Job Cluster {} is Enabled", this.name);
} catch (Exception e) {
String errorMsg = String.format("Exception enabling cluster %s due to %s", name, e.getMessage());
logger.error(errorMsg, e);
sender.tell(new EnableJobClusterResponse(req.requestId, SERVER_ERROR, errorMsg), getSelf());
numJobClusterEnableErrors.increment();
}
if (logger.isTraceEnabled()) {
logger.trace("Enter onJobClusterEnable");
}
}
use of io.mantisrx.server.master.domain.JobClusterDefinitionImpl in project mantis by Netflix.
the class JobClusterActor method onJobClusterUpdateSLA.
@Override
public void onJobClusterUpdateSLA(UpdateJobClusterSLARequest slaRequest) {
if (logger.isTraceEnabled()) {
logger.trace("Enter onJobClusterUpdateSLA {}", slaRequest);
}
ActorRef sender = getSender();
try {
SLA newSla = new SLA(slaRequest.getMin(), slaRequest.getMax(), slaRequest.getCronSpec(), slaRequest.getCronPolicy());
JobClusterDefinitionImpl updatedDefn = new JobClusterDefinitionImpl.Builder().from(jobClusterMetadata.getJobClusterDefinition()).withSla(newSla).build();
boolean isDisabled = jobClusterMetadata.isDisabled();
if (slaRequest.isForceEnable() && jobClusterMetadata.isDisabled()) {
isDisabled = false;
}
IJobClusterMetadata jobCluster = new JobClusterMetadataImpl.Builder().withIsDisabled(isDisabled).withLastJobCount(jobClusterMetadata.getLastJobCount()).withJobClusterDefinition(updatedDefn).build();
updateAndSaveJobCluster(jobCluster);
if (cronManager != null)
cronManager.destroyCron();
this.cronManager = new CronManager(name, getSelf(), newSla);
sender.tell(new UpdateJobClusterSLAResponse(slaRequest.requestId, SUCCESS, name + " SLA updated"), getSelf());
eventPublisher.publishAuditEvent(new LifecycleEventsProto.AuditEvent(LifecycleEventsProto.AuditEvent.AuditEventType.JOB_CLUSTER_UPDATE, jobClusterMetadata.getJobClusterDefinition().getName(), name + " SLA update"));
} catch (IllegalArgumentException e) {
logger.error("Invalid arguement job cluster not updated ", e);
sender.tell(new UpdateJobClusterSLAResponse(slaRequest.requestId, CLIENT_ERROR, name + " Job cluster SLA updation failed " + e.getMessage()), getSelf());
} catch (Exception e) {
logger.error("job cluster not updated ", e);
sender.tell(new UpdateJobClusterSLAResponse(slaRequest.requestId, SERVER_ERROR, name + " Job cluster SLA updation failed " + e.getMessage()), getSelf());
}
if (logger.isTraceEnabled()) {
logger.trace("Exit onJobClusterUpdateSLA {}", slaRequest);
}
}
Aggregations