use of com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException in project hopsworks by logicalclocks.
the class TestAlertManagerConfigTimer method setUp.
@Before
public void setUp() throws ServiceDiscoveryException, AlertManagerConfigFileNotFoundException, AlertManagerConfigReadException, JsonProcessingException {
String alertmanagerConfigPath = TestAlertManagerConfigTimer.class.getResource("/alertmanager.yml").getPath();
alertManagerConfigDBPath = TestAlertManagerConfigTimer.class.getResource("/alertmanagerDB.yml").getPath();
client = Mockito.mock(AlertManagerClient.class);
alertManagerConfigController = new AlertManagerConfigController.Builder().withConfigPath(alertmanagerConfigPath).withClient(client).build();
alertManagerConfigFacade = Mockito.mock(AlertManagerConfigFacade.class);
Mockito.doAnswer((Answer<Void>) invocation -> {
Object[] args = invocation.getArguments();
LOGGER.log(Level.INFO, "Save to database: {0}.", args);
return null;
}).when(alertManagerConfigFacade).save(Mockito.any());
Mockito.doAnswer((Answer<Void>) invocation -> {
Object[] args = invocation.getArguments();
LOGGER.log(Level.INFO, "Update database: {0}.", args);
return null;
}).when(alertManagerConfigFacade).update(Mockito.any());
AlertManagerConfig alertManagerConfig = read(new File(alertManagerConfigDBPath));
AlertManagerConfigEntity alertManagerConfigEntity = new AlertManagerConfigEntity();
alertManagerConfigEntity.setId(1);
alertManagerConfigEntity.setCreated(new Date());
alertManagerConfigEntity.setContent(toJson(alertManagerConfig));
Mockito.when(alertManagerConfigFacade.getLatest()).thenReturn(Optional.of(alertManagerConfigEntity));
alertReceiverFacade = Mockito.mock(AlertReceiverFacade.class);
List<AlertReceiver> receivers = createReceivers();
Mockito.when(alertReceiverFacade.findAll()).thenReturn(receivers);
Mockito.doAnswer((Answer<Optional<AlertReceiver>>) invocation -> {
Object[] args = invocation.getArguments();
Optional<AlertReceiver> alertReceiver = receivers.stream().filter(receiver -> receiver.getName().equals(args[0])).findFirst();
return alertReceiver;
}).when(alertReceiverFacade).findByName(Mockito.any());
alertManagerConfiguration = new AlertManagerConfiguration(client, alertManagerConfigController, alertManagerConfigFacade, alertReceiverFacade);
alertManagerConfigBackup = alertManagerConfigController.read();
alertManagerConfigBackupDB = read(new File(alertManagerConfigDBPath));
}
use of com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException in project hopsworks by logicalclocks.
the class DelaProjectService method downloadDatasetKafka.
@POST
@Path("/downloads/{publicDSId}/kafka")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response downloadDatasetKafka(@Context HttpServletRequest req, @Context SecurityContext sc, @PathParam("publicDSId") String publicDSId, HopsworksTransferDTO.Download downloadDTO) throws DelaException, ServiceException {
Users user = jWTHelper.getUserPrincipal(sc);
Dataset dataset = getDatasetByPublicId(publicDSId);
String certPath = kafkaController.getKafkaCertPaths(project);
Optional<String> kafkaBrokerOpt = kafkaBrokers.getAnyKafkaBroker();
String brokerEndpoint = kafkaBrokerOpt.orElseThrow(() -> new DelaException(RESTCodes.DelaErrorCode.MISCONFIGURED, Level.WARNING, DelaException.Source.KAFKA, "Could not find any active Kafka broker"));
String restEndpoint;
try {
restEndpoint = "https://" + serviceDiscoveryController.constructServiceFQDNWithPort(ServiceDiscoveryController.HopsworksService.HOPSWORKS_APP);
} catch (ServiceDiscoveryException e) {
throw new ServiceException(RESTCodes.ServiceErrorCode.SERVICE_NOT_FOUND, Level.SEVERE, "Could not find Hopsworks service");
}
String keyStore = certPath + "/keystore.jks";
String trustStore = certPath + "/truststore.jks";
KafkaEndpoint kafkaEndpoint = new KafkaEndpoint(brokerEndpoint, restEndpoint, settings.getDELA_DOMAIN(), "" + project.getId(), keyStore, trustStore);
delaWorkerCtrl.advanceDownload(project, dataset, user, downloadDTO, req.getSession().getId(), kafkaEndpoint);
return successResponse(new SuccessJSON(""));
}
Aggregations