Search in sources :

Example 1 with ProtobufModule

use of com.hubspot.jackson.datatype.protobuf.ProtobufModule in project Singularity by HubSpot.

the class SingularityService method initialize.

@Override
public void initialize(final Bootstrap<T> bootstrap) {
    if (!Strings.isNullOrEmpty(System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY))) {
        bootstrap.setConfigurationSourceProvider(new MergingSourceProvider(bootstrap.getConfigurationSourceProvider(), System.getProperty(SINGULARITY_DEFAULT_CONFIGURATION_PROPERTY), bootstrap.getObjectMapper(), new YAMLFactory()));
    }
    final Iterable<? extends Module> additionalModules = checkNotNull(getGuiceModules(bootstrap), "getGuiceModules() returned null");
    final Iterable<? extends Bundle> additionalBundles = checkNotNull(getDropwizardBundles(bootstrap), "getDropwizardBundles() returned null");
    final Iterable<? extends ConfiguredBundle<T>> additionalConfiguredBundles = checkNotNull(getDropwizardConfiguredBundles(bootstrap), "getDropwizardConfiguredBundles() returned null");
    guiceBundle = GuiceBundle.defaultBuilder(SingularityConfiguration.class).modules(new SingularityServiceModule()).modules(new SingularityAuthModule()).modules(additionalModules).build();
    bootstrap.addBundle(guiceBundle);
    bootstrap.addBundle(new CorsBundle());
    bootstrap.addBundle(new ViewBundle<>());
    bootstrap.addBundle(new AssetsBundle("/assets/static/", "/static/"));
    bootstrap.addBundle(new AssetsBundle("/assets/api-docs/", "/api-docs/", "index.html", "api-docs"));
    bootstrap.addBundle(new MigrationsBundle<SingularityConfiguration>() {

        @Override
        public DataSourceFactory getDataSourceFactory(final SingularityConfiguration configuration) {
            return configuration.getDatabaseConfiguration().get();
        }
    });
    for (Bundle bundle : additionalBundles) {
        bootstrap.addBundle(bundle);
    }
    for (ConfiguredBundle<T> configuredBundle : additionalConfiguredBundles) {
        bootstrap.addBundle(configuredBundle);
    }
    bootstrap.getObjectMapper().registerModule(new ProtobufModule());
    bootstrap.getObjectMapper().registerModule(new GuavaModule());
    bootstrap.getObjectMapper().setSerializationInclusion(Include.NON_NULL);
    bootstrap.getObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
Also used : DataSourceFactory(io.dropwizard.db.DataSourceFactory) CorsBundle(com.hubspot.singularity.bundles.CorsBundle) GuiceBundle(com.hubspot.dropwizard.guicier.GuiceBundle) MigrationsBundle(io.dropwizard.migrations.MigrationsBundle) ViewBundle(io.dropwizard.views.ViewBundle) AssetsBundle(io.dropwizard.assets.AssetsBundle) ConfiguredBundle(io.dropwizard.ConfiguredBundle) Bundle(io.dropwizard.Bundle) AssetsBundle(io.dropwizard.assets.AssetsBundle) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) MergingSourceProvider(com.hubspot.singularity.config.MergingSourceProvider) CorsBundle(com.hubspot.singularity.bundles.CorsBundle) ProtobufModule(com.hubspot.jackson.datatype.protobuf.ProtobufModule) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) SingularityConfiguration(com.hubspot.singularity.config.SingularityConfiguration)

Example 2 with ProtobufModule

use of com.hubspot.jackson.datatype.protobuf.ProtobufModule in project Singularity by HubSpot.

the class JavaUtils method newObjectMapper.

public static ObjectMapper newObjectMapper() {
    final ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(Include.NON_NULL);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new ProtobufModule());
    return mapper;
}
Also used : ProtobufModule(com.hubspot.jackson.datatype.protobuf.ProtobufModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule)

Example 3 with ProtobufModule

use of com.hubspot.jackson.datatype.protobuf.ProtobufModule in project Singularity by HubSpot.

the class SingularityRunnerBaseModule method providesYamlMapper.

@Provides
@Singleton
@Named(YAML)
public ObjectMapper providesYamlMapper() {
    final YAMLFactory yamlFactory = new YAMLFactory();
    yamlFactory.disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER);
    final ObjectMapper mapper = new ObjectMapper(yamlFactory);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    mapper.registerModule(new GuavaModule());
    mapper.registerModule(new ProtobufModule());
    return mapper;
}
Also used : ProtobufModule(com.hubspot.jackson.datatype.protobuf.ProtobufModule) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) Named(com.google.inject.name.Named) Singleton(com.google.inject.Singleton) Provides(com.google.inject.Provides)

Example 4 with ProtobufModule

use of com.hubspot.jackson.datatype.protobuf.ProtobufModule in project Singularity by HubSpot.

the class SingularityMesosTaskBuilderTest method createMocks.

@Before
public void createMocks() {
    pendingTask = new SingularityPendingTaskBuilder().setPendingTaskId(new SingularityPendingTaskId("test", "1", 0, 1, PendingType.IMMEDIATE, 0)).setUser(user).build();
    final SingularitySlaveAndRackHelper slaveAndRackHelper = mock(SingularitySlaveAndRackHelper.class);
    final ExecutorIdGenerator idGenerator = mock(ExecutorIdGenerator.class);
    when(idGenerator.getNextExecutorId()).then(new CreateFakeId());
    objectMapper = new ObjectMapper();
    objectMapper.registerModule(new ProtobufModule());
    objectMapper.registerModule(new GuavaModule());
    builder = new SingularityMesosTaskBuilder(objectMapper, idGenerator, configuration, new MesosProtosUtils(objectMapper));
    taskResources = new Resources(1, 1, 0, 0);
    executorResources = new Resources(0.1, 1, 0, 0);
    when(slaveAndRackHelper.getRackId(offer)).thenReturn(Optional.absent());
    when(slaveAndRackHelper.getMaybeTruncatedHost(offer)).thenReturn("host");
    when(slaveAndRackHelper.getRackIdOrDefault(offer)).thenReturn("DEFAULT");
    offer = Offer.newBuilder().setAgentId(AgentID.newBuilder().setValue("1")).setId(OfferID.newBuilder().setValue("1")).setFrameworkId(FrameworkID.newBuilder().setValue("1")).setHostname("test").build();
    offerHolder = new SingularityOfferHolder(Collections.singletonList(offer), 1, "DEFAULT", offer.getAgentId().getValue(), offer.getHostname(), Collections.emptyMap(), Collections.emptyMap());
}
Also used : MesosProtosUtils(com.hubspot.singularity.helpers.MesosProtosUtils) ExecutorIdGenerator(com.hubspot.singularity.data.ExecutorIdGenerator) SingularityPendingTaskId(com.hubspot.singularity.SingularityPendingTaskId) ProtobufModule(com.hubspot.jackson.datatype.protobuf.ProtobufModule) Resources(com.hubspot.mesos.Resources) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GuavaModule(com.fasterxml.jackson.datatype.guava.GuavaModule) SingularityPendingTaskBuilder(com.hubspot.singularity.SingularityPendingTaskBuilder) Before(org.junit.Before)

Example 5 with ProtobufModule

use of com.hubspot.jackson.datatype.protobuf.ProtobufModule in project Singularity by HubSpot.

the class JavaUtilsTest method testSingularityTaskIdSerialization.

@Test
public void testSingularityTaskIdSerialization() throws Exception {
    ObjectMapper om = Jackson.newObjectMapper().setSerializationInclusion(Include.NON_NULL).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).registerModule(new ProtobufModule());
    SingularityTaskId taskId = new SingularityTaskId("rid", "did", 100, 1, "host", "rack");
    String id = taskId.getId();
    SingularityTaskId fromId = SingularityTaskId.valueOf(id);
    SingularityTaskId fromJson = om.readValue(om.writeValueAsBytes(taskId), SingularityTaskId.class);
    assertEquals(taskId, fromId);
    assertEquals(taskId, fromJson);
    assertEquals(fromId, fromJson);
}
Also used : ProtobufModule(com.hubspot.jackson.datatype.protobuf.ProtobufModule) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ProtobufModule (com.hubspot.jackson.datatype.protobuf.ProtobufModule)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 GuavaModule (com.fasterxml.jackson.datatype.guava.GuavaModule)4 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)2 Provides (com.google.inject.Provides)1 Singleton (com.google.inject.Singleton)1 Named (com.google.inject.name.Named)1 GuiceBundle (com.hubspot.dropwizard.guicier.GuiceBundle)1 Resources (com.hubspot.mesos.Resources)1 SingularityPendingTaskBuilder (com.hubspot.singularity.SingularityPendingTaskBuilder)1 SingularityPendingTaskId (com.hubspot.singularity.SingularityPendingTaskId)1 CorsBundle (com.hubspot.singularity.bundles.CorsBundle)1 MergingSourceProvider (com.hubspot.singularity.config.MergingSourceProvider)1 SingularityConfiguration (com.hubspot.singularity.config.SingularityConfiguration)1 ExecutorIdGenerator (com.hubspot.singularity.data.ExecutorIdGenerator)1 MesosProtosUtils (com.hubspot.singularity.helpers.MesosProtosUtils)1 Bundle (io.dropwizard.Bundle)1 ConfiguredBundle (io.dropwizard.ConfiguredBundle)1 AssetsBundle (io.dropwizard.assets.AssetsBundle)1 DataSourceFactory (io.dropwizard.db.DataSourceFactory)1