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);
}
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;
}
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;
}
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());
}
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);
}
Aggregations