Search in sources :

Example 31 with ServiceDiscoveryException

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));
}
Also used : YAMLGenerator(com.fasterxml.jackson.dataformat.yaml.YAMLGenerator) AlertType(io.hops.hopsworks.persistence.entity.alertmanager.AlertType) FeatureGroupAlert(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.FeatureGroupAlert) Date(java.util.Date) Random(java.util.Random) AlertSeverity(io.hops.hopsworks.persistence.entity.alertmanager.AlertSeverity) AlertManagerConfigController(io.hops.hopsworks.alerting.config.AlertManagerConfigController) AlertManagerClient(io.hops.hopsworks.alerting.api.AlertManagerClient) JSONObject(org.json.JSONObject) AlertManagerConfiguration(io.hops.hopsworks.alert.AlertManagerConfiguration) After(org.junit.After) JobAlert(io.hops.hopsworks.persistence.entity.jobs.description.JobAlert) AlertManagerConfigFacade(io.hops.hopsworks.alert.dao.AlertManagerConfigFacade) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) ValidationRuleAlertStatus(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.datavalidation.alert.ValidationRuleAlertStatus) SlackConfig(io.hops.hopsworks.alerting.config.dto.SlackConfig) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) Jobs(io.hops.hopsworks.persistence.entity.jobs.description.Jobs) Featuregroup(io.hops.hopsworks.persistence.entity.featurestore.featuregroup.Featuregroup) Logger(java.util.logging.Logger) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) ProjectServiceAlert(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlert) List(java.util.List) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) JobAlertStatus(io.hops.hopsworks.persistence.entity.jobs.description.JobAlertStatus) Optional(java.util.Optional) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) EmailConfig(io.hops.hopsworks.alerting.config.dto.EmailConfig) ProjectServiceEnum(io.hops.hopsworks.persistence.entity.project.service.ProjectServiceEnum) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) Project(io.hops.hopsworks.persistence.entity.project.Project) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) Answer(org.mockito.stubbing.Answer) AlertManagerConfigFileNotFoundException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigFileNotFoundException) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) PagerdutyConfig(io.hops.hopsworks.alerting.config.dto.PagerdutyConfig) Before(org.junit.Before) AlertManagerConfigEntity(io.hops.hopsworks.persistence.entity.alertmanager.AlertManagerConfigEntity) AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Featurestore(io.hops.hopsworks.persistence.entity.featurestore.Featurestore) ProjectServiceAlertStatus(io.hops.hopsworks.persistence.entity.project.alert.ProjectServiceAlertStatus) File(java.io.File) Mockito(org.mockito.Mockito) AlertReceiverFacade(io.hops.hopsworks.alert.dao.AlertReceiverFacade) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) AlertManagerConfig(io.hops.hopsworks.alerting.config.dto.AlertManagerConfig) Optional(java.util.Optional) AlertReceiver(io.hops.hopsworks.persistence.entity.alertmanager.AlertReceiver) AlertManagerConfigFacade(io.hops.hopsworks.alert.dao.AlertManagerConfigFacade) Date(java.util.Date) AlertManagerClient(io.hops.hopsworks.alerting.api.AlertManagerClient) AlertReceiverFacade(io.hops.hopsworks.alert.dao.AlertReceiverFacade) File(java.io.File) AlertManagerConfigEntity(io.hops.hopsworks.persistence.entity.alertmanager.AlertManagerConfigEntity) AlertManagerConfiguration(io.hops.hopsworks.alert.AlertManagerConfiguration) Before(org.junit.Before)

Example 32 with ServiceDiscoveryException

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(""));
}
Also used : ServiceException(io.hops.hopsworks.exceptions.ServiceException) Dataset(io.hops.hopsworks.persistence.entity.dataset.Dataset) SuccessJSON(io.hops.hopsworks.dela.old_dto.SuccessJSON) KafkaEndpoint(io.hops.hopsworks.dela.old_dto.KafkaEndpoint) ServiceDiscoveryException(com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException) Users(io.hops.hopsworks.persistence.entity.user.Users) DelaException(io.hops.hopsworks.exceptions.DelaException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

ServiceDiscoveryException (com.logicalclocks.servicediscoverclient.exceptions.ServiceDiscoveryException)32 IOException (java.io.IOException)16 ServiceException (io.hops.hopsworks.exceptions.ServiceException)11 Service (com.logicalclocks.servicediscoverclient.service.Service)7 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)6 SQLException (java.sql.SQLException)4 Level (java.util.logging.Level)4 TransactionAttribute (javax.ejb.TransactionAttribute)4 FeaturestoreStorageConnectorDTO (io.hops.hopsworks.common.featurestore.storageconnectors.FeaturestoreStorageConnectorDTO)3 ServiceDiscoveryController (io.hops.hopsworks.common.hosts.ServiceDiscoveryController)3 Dataset (io.hops.hopsworks.persistence.entity.dataset.Dataset)3 Featurestore (io.hops.hopsworks.persistence.entity.featurestore.Featurestore)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 List (java.util.List)3 HttpHost (org.apache.http.HttpHost)3 TemplateException (freemarker.template.TemplateException)2 FeaturestoreHopsfsConnectorDTO (io.hops.hopsworks.common.featurestore.storageconnectors.hopsfs.FeaturestoreHopsfsConnectorDTO)2 Settings (io.hops.hopsworks.common.util.Settings)2 ProjectException (io.hops.hopsworks.exceptions.ProjectException)2