Search in sources :

Example 1 with PolicyTransformException

use of com.thinkbiganalytics.policy.PolicyTransformException in project kylo by Teradata.

the class SchemaDiscoveryRestController method uploadFile.

@POST
@Path("/hive/sample-file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Determines the schema of the provided file.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the schema.", response = Schema.class), @ApiResponse(code = 500, message = "The schema could not be determined.", response = RestResponseStatus.class) })
public Response uploadFile(@FormDataParam("parser") String parserDescriptor, @FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition fileMetaData) throws Exception {
    Schema schema;
    SchemaParserAnnotationTransformer transformer = new SchemaParserAnnotationTransformer();
    try {
        SchemaParserDescriptor descriptor = ObjectMapperSerializer.deserialize(parserDescriptor, SchemaParserDescriptor.class);
        FileSchemaParser p = transformer.fromUiModel(descriptor);
        // TODO: Detect charset
        schema = p.parse(fileInputStream, Charset.defaultCharset(), TableSchemaType.HIVE);
    } catch (IOException e) {
        throw new WebApplicationException(e.getMessage());
    } catch (PolicyTransformException e) {
        log.warn("Failed to convert parser", e);
        throw new InternalServerErrorException(STRINGS.getString("discovery.transformError"), e);
    }
    return Response.ok(schema).build();
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Schema(com.thinkbiganalytics.discovery.schema.Schema) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) IOException(java.io.IOException) PolicyTransformException(com.thinkbiganalytics.policy.PolicyTransformException) FileSchemaParser(com.thinkbiganalytics.discovery.parser.FileSchemaParser) SchemaParserDescriptor(com.thinkbiganalytics.discovery.model.SchemaParserDescriptor) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with PolicyTransformException

use of com.thinkbiganalytics.policy.PolicyTransformException in project kylo by Teradata.

the class PreconditionPolicyTransformer method getPreconditionObligationGroups.

public List<ObligationGroup> getPreconditionObligationGroups() {
    List<ObligationGroup> policies = new ArrayList<>();
    if (preconditionRules != null) {
        for (PreconditionRule rule : preconditionRules) {
            try {
                Precondition policy = PreconditionAnnotationTransformer.instance().fromUiModel(rule);
                policies.addAll(Lists.newArrayList(policy.buildPreconditionObligations()));
            } catch (PolicyTransformException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return policies;
}
Also used : Precondition(com.thinkbiganalytics.policy.precondition.Precondition) ArrayList(java.util.ArrayList) PolicyTransformException(com.thinkbiganalytics.policy.PolicyTransformException) ObligationGroup(com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup) PreconditionRule(com.thinkbiganalytics.policy.rest.model.PreconditionRule)

Example 3 with PolicyTransformException

use of com.thinkbiganalytics.policy.PolicyTransformException in project kylo by Teradata.

the class PreconditionPolicyTransformer method getPreconditionPolicies.

public List<Precondition> getPreconditionPolicies() {
    List<Precondition> policies = new ArrayList<>();
    if (preconditionRules != null) {
        for (PreconditionRule rule : preconditionRules) {
            try {
                Precondition policy = PreconditionAnnotationTransformer.instance().fromUiModel(rule);
                policies.add(policy);
            } catch (PolicyTransformException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return policies;
}
Also used : Precondition(com.thinkbiganalytics.policy.precondition.Precondition) ArrayList(java.util.ArrayList) PolicyTransformException(com.thinkbiganalytics.policy.PolicyTransformException) PreconditionRule(com.thinkbiganalytics.policy.rest.model.PreconditionRule)

Example 4 with PolicyTransformException

use of com.thinkbiganalytics.policy.PolicyTransformException in project kylo by Teradata.

the class ServiceLevelAgreementMetricTransformerHelper method getServiceLevelAgreement.

public ServiceLevelAgreement getServiceLevelAgreement(ServiceLevelAgreementGroup serviceLevelAgreement) {
    ServiceLevelAgreement transformedSla = new ServiceLevelAgreement();
    transformedSla.setId(serviceLevelAgreement.getId());
    transformedSla.setName(serviceLevelAgreement.getName());
    transformedSla.setDescription(serviceLevelAgreement.getDescription());
    for (ServiceLevelAgreementRule rule : serviceLevelAgreement.getRules()) {
        try {
            ObligationGroup group = new ObligationGroup();
            Metric policy = ServiceLevelAgreementMetricTransformer.instance().fromUiModel(rule);
            Obligation obligation = new Obligation(policy.getDescription());
            obligation.setMetrics(Lists.newArrayList(policy));
            group.addObligation(obligation);
            group.setCondition(rule.getCondition().name());
            transformedSla.addGroup(group);
        } catch (PolicyTransformException e) {
            throw new RuntimeException(e);
        }
    }
    return transformedSla;
}
Also used : Obligation(com.thinkbiganalytics.metadata.rest.model.sla.Obligation) ServiceLevelAgreement(com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement) Metric(com.thinkbiganalytics.metadata.sla.api.Metric) PolicyTransformException(com.thinkbiganalytics.policy.PolicyTransformException) ObligationGroup(com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup)

Example 5 with PolicyTransformException

use of com.thinkbiganalytics.policy.PolicyTransformException in project kylo by Teradata.

the class ServiceLevelAgreementMetricTransformerHelper method getActionConfigurations.

public List<ServiceLevelAgreementActionConfiguration> getActionConfigurations(ServiceLevelAgreementGroup serviceLevelAgreement) {
    List<ServiceLevelAgreementActionConfiguration> actionConfigurations = new ArrayList<>();
    if (serviceLevelAgreement.getActionConfigurations() != null) {
        for (ServiceLevelAgreementActionUiConfigurationItem agreementActionUiConfigurationItem : serviceLevelAgreement.getActionConfigurations()) {
            try {
                ServiceLevelAgreementActionConfiguration actionConfiguration = ServiceLevelAgreementActionConfigTransformer.instance().fromUiModel(agreementActionUiConfigurationItem);
                actionConfigurations.add(actionConfiguration);
            } catch (PolicyTransformException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return actionConfigurations;
}
Also used : ArrayList(java.util.ArrayList) PolicyTransformException(com.thinkbiganalytics.policy.PolicyTransformException) ServiceLevelAgreementActionConfiguration(com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration)

Aggregations

PolicyTransformException (com.thinkbiganalytics.policy.PolicyTransformException)5 ArrayList (java.util.ArrayList)3 ObligationGroup (com.thinkbiganalytics.metadata.rest.model.sla.ObligationGroup)2 Precondition (com.thinkbiganalytics.policy.precondition.Precondition)2 PreconditionRule (com.thinkbiganalytics.policy.rest.model.PreconditionRule)2 SchemaParserDescriptor (com.thinkbiganalytics.discovery.model.SchemaParserDescriptor)1 FileSchemaParser (com.thinkbiganalytics.discovery.parser.FileSchemaParser)1 Schema (com.thinkbiganalytics.discovery.schema.Schema)1 Obligation (com.thinkbiganalytics.metadata.rest.model.sla.Obligation)1 ServiceLevelAgreement (com.thinkbiganalytics.metadata.rest.model.sla.ServiceLevelAgreement)1 Metric (com.thinkbiganalytics.metadata.sla.api.Metric)1 ServiceLevelAgreementActionConfiguration (com.thinkbiganalytics.metadata.sla.api.ServiceLevelAgreementActionConfiguration)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 IOException (java.io.IOException)1 Consumes (javax.ws.rs.Consumes)1 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1