Search in sources :

Example 1 with Builder

use of org.apache.mesos.Protos.FrameworkInfo.Builder in project incubator-myriad by apache.

the class MesosModule method providesSchedulerDriver.

@Provides
@Singleton
SchedulerDriver providesSchedulerDriver(MyriadScheduler scheduler, MyriadConfiguration cfg, SchedulerState schedulerState) {
    Builder frameworkInfoBuilder = FrameworkInfo.newBuilder().setUser("").setName(cfg.getFrameworkName()).setCheckpoint(cfg.isCheckpoint()).setFailoverTimeout(cfg.getFrameworkFailoverTimeout());
    frameworkInfoBuilder.setRole(cfg.getFrameworkRole());
    Optional<FrameworkID> optFrameId = schedulerState.getFrameworkID();
    if (optFrameId.isPresent()) {
        FrameworkID frameworkId = optFrameId.get();
        LOGGER.info("Attempting to re-register with frameworkId: {}", frameworkId.getValue());
        frameworkInfoBuilder.setId(frameworkId);
    }
    String mesosAuthenticationPrincipal = cfg.getMesosAuthenticationPrincipal();
    String mesosAuthenticationSecretFilename = cfg.getMesosAuthenticationSecretFilename();
    if (StringUtils.isNotEmpty(mesosAuthenticationPrincipal)) {
        frameworkInfoBuilder.setPrincipal(mesosAuthenticationPrincipal);
        Credential.Builder credentialBuilder = Credential.newBuilder();
        credentialBuilder.setPrincipal(mesosAuthenticationPrincipal);
        if (StringUtils.isNotEmpty(mesosAuthenticationSecretFilename)) {
            try {
                credentialBuilder.setSecretBytes(ByteString.readFrom(new FileInputStream(mesosAuthenticationSecretFilename)));
            } catch (FileNotFoundException ex) {
                LOGGER.error("Mesos authentication secret file was not found", ex);
                throw new RuntimeException(ex);
            } catch (IOException ex) {
                LOGGER.error("Error reading Mesos authentication secret file", ex);
                throw new RuntimeException(ex);
            }
        }
        return new MesosSchedulerDriver(scheduler, frameworkInfoBuilder.build(), cfg.getMesosMaster(), credentialBuilder.build());
    } else {
        return new MesosSchedulerDriver(scheduler, frameworkInfoBuilder.build(), cfg.getMesosMaster());
    }
}
Also used : Credential(org.apache.mesos.Protos.Credential) Builder(org.apache.mesos.Protos.FrameworkInfo.Builder) FileNotFoundException(java.io.FileNotFoundException) FrameworkID(org.apache.mesos.Protos.FrameworkID) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) MesosSchedulerDriver(org.apache.mesos.MesosSchedulerDriver) FileInputStream(java.io.FileInputStream) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Aggregations

Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 ByteString (com.google.protobuf.ByteString)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MesosSchedulerDriver (org.apache.mesos.MesosSchedulerDriver)1 Credential (org.apache.mesos.Protos.Credential)1 FrameworkID (org.apache.mesos.Protos.FrameworkID)1 Builder (org.apache.mesos.Protos.FrameworkInfo.Builder)1