Search in sources :

Example 1 with JobClusterDefinitionImpl

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();
    }
}
Also used : Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) Parameter(io.mantisrx.runtime.parameter.Parameter) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) Test(org.junit.Test)

Example 2 with JobClusterDefinitionImpl

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();
    }
}
Also used : Label(io.mantisrx.common.Label) ArrayList(java.util.ArrayList) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) InvalidJobException(io.mantisrx.runtime.command.InvalidJobException) Parameter(io.mantisrx.runtime.parameter.Parameter) JobDefinition(io.mantisrx.server.master.domain.JobDefinition) Test(org.junit.Test)

Example 3 with JobClusterDefinitionImpl

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);
    }
}
Also used : ActorRef(akka.actor.ActorRef) JobClusterConfig(io.mantisrx.server.master.domain.JobClusterConfig) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) LifecycleEventsProto(io.mantisrx.master.events.LifecycleEventsProto) UpdateJobClusterLabelsResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterLabelsResponse) TriggerNotFoundException(com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException) SchedulerException(com.netflix.fenzo.triggers.exceptions.SchedulerException) JobClusterAlreadyExistsException(io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException)

Example 4 with JobClusterDefinitionImpl

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");
    }
}
Also used : EnableJobClusterResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.EnableJobClusterResponse) ActorRef(akka.actor.ActorRef) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) LifecycleEventsProto(io.mantisrx.master.events.LifecycleEventsProto) TriggerNotFoundException(com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException) SchedulerException(com.netflix.fenzo.triggers.exceptions.SchedulerException) JobClusterAlreadyExistsException(io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException)

Example 5 with JobClusterDefinitionImpl

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);
    }
}
Also used : ActorRef(akka.actor.ActorRef) JobClusterDefinitionImpl(io.mantisrx.server.master.domain.JobClusterDefinitionImpl) SLA(io.mantisrx.server.master.domain.SLA) TriggerNotFoundException(com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException) SchedulerException(com.netflix.fenzo.triggers.exceptions.SchedulerException) JobClusterAlreadyExistsException(io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException) UpdateJobClusterSLAResponse(io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.UpdateJobClusterSLAResponse) LifecycleEventsProto(io.mantisrx.master.events.LifecycleEventsProto)

Aggregations

JobClusterDefinitionImpl (io.mantisrx.server.master.domain.JobClusterDefinitionImpl)34 Test (org.junit.Test)25 TestKit (akka.testkit.javadsl.TestKit)17 JobClusterManagerProto (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto)17 Label (io.mantisrx.common.Label)13 GetJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterRequest)9 GetJobClusterResponse (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.GetJobClusterResponse)9 InvalidJobException (io.mantisrx.runtime.command.InvalidJobException)9 JobDefinition (io.mantisrx.server.master.domain.JobDefinition)9 JobClusterAlreadyExistsException (io.mantisrx.server.master.persistence.exceptions.JobClusterAlreadyExistsException)9 ActorRef (akka.actor.ActorRef)8 ArrayList (java.util.ArrayList)8 SchedulerException (com.netflix.fenzo.triggers.exceptions.SchedulerException)7 TriggerNotFoundException (com.netflix.fenzo.triggers.exceptions.TriggerNotFoundException)7 LifecycleEventsProto (io.mantisrx.master.events.LifecycleEventsProto)6 Parameter (io.mantisrx.runtime.parameter.Parameter)5 IJobClusterMetadata (io.mantisrx.master.jobcluster.IJobClusterMetadata)4 JobClusterConfig (io.mantisrx.server.master.domain.JobClusterConfig)4 DisableJobClusterRequest (io.mantisrx.master.jobcluster.proto.JobClusterManagerProto.DisableJobClusterRequest)3 SchedulingInfo (io.mantisrx.runtime.descriptor.SchedulingInfo)3