http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-process/src/test/resources/unittest.conf ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-process/src/test/resources/unittest.conf b/eagle-core/eagle-alert/eagle-alert-process/src/test/resources/unittest.conf index c82c20b..12a55fe 100644 --- a/eagle-core/eagle-alert/eagle-alert-process/src/test/resources/unittest.conf +++ b/eagle-core/eagle-alert/eagle-alert-process/src/test/resources/unittest.conf @@ -16,7 +16,7 @@ "zkConnectionTimeoutMS" : 15000, "consumerGroupId" : "EagleConsumer", "fetchSize" : 1048586, - "deserializerClass" : "eagle.security.auditlog.HdfsAuditLogKafkaDeserializer", + "deserializerClass" : "org.apache.eagle.security.auditlog.HdfsAuditLogKafkaDeserializer", "transactionZKServers" : "localhost", "transactionZKPort" : 2181, "transactionZKRoot" : "/brokers/topics", @@ -25,7 +25,7 @@ "alertExecutorConfigs" : { "hdfsAuditLogAlertExecutor" : { "parallelism" : 2, - "partitioner" : "eagle.alert.policy.DefaultPolicyPartitioner" + "partitioner" : "org.apache.eagle.alert.policy.DefaultPolicyPartitioner" "needValidation" : "true" } },
http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/AlertPolicyValidateProvider.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/AlertPolicyValidateProvider.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/AlertPolicyValidateProvider.java deleted file mode 100644 index 9d490c8..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/AlertPolicyValidateProvider.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert; - -import java.util.List; - -import eagle.log.entity.GenericServiceAPIResponseEntity; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonTypeInfo; -import com.fasterxml.jackson.databind.Module; - -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible=true) -@JsonIgnoreProperties(ignoreUnknown = true) -public abstract class AlertPolicyValidateProvider { - public String type; - - public abstract GenericServiceAPIResponseEntity<String> validate(); - - public abstract String PolicyType(); - - public abstract List<Module> BindingModules(); -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/PolicyValidateResource.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/PolicyValidateResource.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/PolicyValidateResource.java deleted file mode 100644 index 01c2e8a..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/PolicyValidateResource.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ServiceLoader; - -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import eagle.dataproc.core.JsonSerDeserUtils; -import eagle.log.entity.GenericServiceAPIResponseEntity; -import com.fasterxml.jackson.databind.Module; - -@Path("/policy/validate") -public class PolicyValidateResource { - - public static Logger LOG = LoggerFactory.getLogger(PolicyValidateResource.class); - - @SuppressWarnings({"rawtypes"}) - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public GenericServiceAPIResponseEntity validatePolicy(String policyToValidate) { - ServiceLoader<AlertPolicyValidateProvider> loader = ServiceLoader.load(AlertPolicyValidateProvider.class); - Iterator<AlertPolicyValidateProvider> iter = loader.iterator(); - List<Module> modules = new ArrayList<Module>(); - while(iter.hasNext()) { - AlertPolicyValidateProvider factory = iter.next(); - LOG.info("Supported policy type : " + factory.PolicyType()); - modules.addAll(factory.BindingModules()); - } - AlertPolicyValidateProvider policyValidate = null; - try { - policyValidate = JsonSerDeserUtils.deserialize(policyToValidate, AlertPolicyValidateProvider.class, modules); - } - catch (Exception ex) { - LOG.error("Fail consutructing AlertPolicyValidateProvider ", ex); - } - return policyValidate.validate(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/SiddhiAlertPolicyValidateProvider.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/SiddhiAlertPolicyValidateProvider.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/SiddhiAlertPolicyValidateProvider.java deleted file mode 100644 index f707f78..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/SiddhiAlertPolicyValidateProvider.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import eagle.service.generic.GenericEntityServiceResource; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.wso2.siddhi.core.ExecutionPlanRuntime; -import org.wso2.siddhi.core.SiddhiManager; - -import eagle.alert.common.AlertConstants; -import eagle.alert.entity.AlertStreamSchemaEntity; -import eagle.alert.siddhi.AttributeType; -import eagle.log.entity.GenericServiceAPIResponseEntity; -import eagle.common.DateTimeUtil; -import com.fasterxml.jackson.databind.Module; -import com.fasterxml.jackson.databind.jsontype.NamedType; -import com.fasterxml.jackson.databind.module.SimpleModule; - -public class SiddhiAlertPolicyValidateProvider extends AlertPolicyValidateProvider{ - - public String type; - public List<String> streamNames; - public String policyDefinition; - public static Logger LOG = LoggerFactory.getLogger(PolicyValidateResource.class); - public static final String EXECUTION_PLAN_NAME = "query"; - - @SuppressWarnings({"unchecked"}) - public String getStreamDef(String streamName) { - GenericEntityServiceResource resource = new GenericEntityServiceResource(); - String startTime = "1969-01-01 00:00:00"; - String endTime = DateTimeUtil.millisecondsToHumanDateWithSeconds(Long.MAX_VALUE); - int pageSize = 1000; - String query = AlertConstants.ALERT_STREAM_SCHEMA_SERVICE_ENDPOINT_NAME + "[@streamName=\"" + streamName + "\"]{*}"; - GenericServiceAPIResponseEntity<AlertStreamSchemaEntity> streamResponse = resource.search(query, startTime, endTime, pageSize, null, false, false, 0L, 0, true, 0, null, false); - List<AlertStreamSchemaEntity> list = streamResponse.getObj(); - - Map<String, String> map = new HashMap<String, String>(); - for(AlertStreamSchemaEntity entity : list){ - map.put(entity.getTags().get("attrName"), entity.getAttrType()); - } - StringBuilder sb = new StringBuilder(); - sb.append("dataobj object,"); - for(Map.Entry<String, String> entry : map.entrySet()){ - String attrName = entry.getKey(); - sb.append(attrName); - sb.append(" "); - String attrType = entry.getValue(); - if(attrType.equalsIgnoreCase(AttributeType.STRING.name())){ - sb.append("string"); - }else if(attrType.equalsIgnoreCase(AttributeType.INTEGER.name())){ - sb.append("int"); - }else if(attrType.equalsIgnoreCase(AttributeType.LONG.name())){ - sb.append("long"); - }else if(attrType.equalsIgnoreCase(AttributeType.BOOL.name())){ - sb.append("bool"); - }else{ - LOG.error("AttrType is not recognized, ignore : " + attrType); - } - sb.append(","); - } - if(sb.length() > 0){ - sb.deleteCharAt(sb.length()-1); - } - - String siddhiStreamDefFormat = "define stream " + streamName + " (" + "%s" + ");"; - String streamDef = String.format(siddhiStreamDefFormat, sb.toString()); - return streamDef; - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public GenericServiceAPIResponseEntity validate() { - GenericServiceAPIResponseEntity result = new GenericServiceAPIResponseEntity(); - SiddhiManager siddhiManager = new SiddhiManager(); - ExecutionPlanRuntime executionPlanRuntime = null; - try { - String streamDefs = new String(); - for(String streamName : streamNames){ - //String streamDef = SiddhiStreamMetadataUtils.convertToStreamDef(streamName); - //We don't use SiddhiStreamMetadataUtils, for it only consume one dataSource - String streamDef = getStreamDef(streamName); - LOG.info("Siddhi stream definition : " + streamDef); - streamDefs += streamDef; - } - - String executionPlan = streamDefs + " @info(name = '" + EXECUTION_PLAN_NAME + "') " + policyDefinition; - executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(executionPlan); - } - catch (Exception ex) { - result.setSuccess(false); - result.setException(ex); - return result; - } - finally { - if (executionPlanRuntime != null) { - executionPlanRuntime.shutdown(); - } - } - result.setSuccess(true); - return result; - } - - @Override - public String PolicyType() { - return "siddhiCEPEngine"; - } - - @Override - public List<Module> BindingModules() { - Module module = new SimpleModule("policyValidate").registerSubtypes(new NamedType(SiddhiAlertPolicyValidateProvider.class, PolicyType())); - return Arrays.asList(module); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolvable.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolvable.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolvable.java deleted file mode 100644 index f8258cc..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolvable.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert.resolver; - -import java.util.List; - -/** - * @param <R> - * @param <V> - * @since 6/16/15 - */ -public interface AttributeResolvable<R extends GenericAttributeResolveRequest, V> { - /** - * @param request request type - * @return List<V> - * @throws AttributeResolveException - */ - List<V> resolve(R request) throws AttributeResolveException; - - /** - * validate request - * @throws BadAttributeResolveRequestException - */ - void validateRequest(R request) throws BadAttributeResolveRequestException; - - /** - * @return Class<R> - */ - Class<R> getRequestClass(); -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveException.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveException.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveException.java deleted file mode 100644 index 7b1d6f5..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveException.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert.resolver; - -/** - * @since 6/16/15 - */ -public class AttributeResolveException extends Exception { - public AttributeResolveException(String s, Exception e) { super(s,e); } - public AttributeResolveException(Exception e) { super(e); } - public AttributeResolveException(String s) { super(s); } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveResource.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveResource.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveResource.java deleted file mode 100644 index 3a87d32..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveResource.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert.resolver; - -import eagle.log.entity.GenericServiceAPIResponseEntity; -import eagle.service.common.EagleExceptionWrapper; -import com.fasterxml.jackson.databind.ObjectMapper; - -import javax.ws.rs.*; -import java.io.InputStream; -import java.util.List; - -/** - * @since 6/17/15 - */ -@Path("/stream") -public class AttributeResolveResource { - @POST - @Path("attributeresolve") - @Consumes({"application/json"}) - @Produces({"application/json"}) - public GenericServiceAPIResponseEntity attributeResolve(InputStream request, - @QueryParam("resolver") String resolver){ - GenericServiceAPIResponseEntity response = new GenericServiceAPIResponseEntity(); - try { - if(resolver == null) throw new AttributeResolveException("resolver is null"); - AttributeResolvable resolvable = AttributeResolverFactory.getAttributeResolver(resolver); - ObjectMapper objectMapper = new ObjectMapper(); - Class<?> resolveRequestClass = resolvable.getRequestClass(); - if(resolveRequestClass == null) throw new AttributeResolveException("Request class is null for resolver "+resolver); - GenericAttributeResolveRequest resolveRequest = (GenericAttributeResolveRequest) objectMapper.readValue(request, resolvable.getRequestClass()); - resolvable.validateRequest(resolveRequest); - List result = resolvable.resolve(resolveRequest); - response.setSuccess(true); - response.setObj(result); - } catch (Exception e) { - response.setSuccess(false); - response.setException(EagleExceptionWrapper.wrap(e)); - return response; - } - return response; - } - - @GET - @Path("attributeresolve") - @Produces({"application/json"}) - public GenericServiceAPIResponseEntity attributeResolver( - @QueryParam("resolver") String resolver, @QueryParam("site") String site, @QueryParam("query") String query){ - GenericServiceAPIResponseEntity response = new GenericServiceAPIResponseEntity(); - try { - if(resolver == null) throw new AttributeResolveException("resolver is null"); - AttributeResolvable resolvable = AttributeResolverFactory.getAttributeResolver(resolver); - Class<?> resolveRequestClass = resolvable.getRequestClass(); - if(resolveRequestClass == null) throw new AttributeResolveException("Request class is null for resolver "+resolver); - GenericAttributeResolveRequest resolveRequest = new GenericAttributeResolveRequest(query,site); - resolvable.validateRequest(resolveRequest); - List result = resolvable.resolve(resolveRequest); - response.setSuccess(true); - response.setObj(result); - } catch (Exception e) { - response.setSuccess(false); - response.setException(EagleExceptionWrapper.wrap(e)); - return response; - } - return response; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveResponse.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveResponse.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveResponse.java deleted file mode 100644 index 9b70a29..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolveResponse.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert.resolver; - -import java.util.List; - -public class AttributeResolveResponse<V> { - private String exception; - private List<V> values; - - public List<V> getValues() { - return values; - } - - public void setValues(List<V> values) { - this.values = values; - } - - public String getException() { - return exception; - } - - public void setException(String exception) { - this.exception = exception; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolverFactory.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolverFactory.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolverFactory.java deleted file mode 100644 index 1771d0f..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/AttributeResolverFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert.resolver; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** -* @since 6/16/15 -*/ -public final class AttributeResolverFactory { - private final static Map<String,AttributeResolvable> fieldResolvableCache = Collections.synchronizedMap(new HashMap<String,AttributeResolvable>()); - public static AttributeResolvable getAttributeResolver(String fieldResolverName) throws AttributeResolveException { - AttributeResolvable instance; - if(fieldResolvableCache.containsKey(fieldResolverName)){ - instance = fieldResolvableCache.get(fieldResolverName); - } else { - try { - instance = (AttributeResolvable) Class.forName(fieldResolverName).newInstance(); - fieldResolvableCache.put(fieldResolverName, instance); - } catch (ClassNotFoundException e) { - throw new AttributeResolveException("Attribute Resolver in type of "+fieldResolverName+" is not found",e); - } catch (InstantiationException | IllegalAccessException e) { - throw new AttributeResolveException(e); - } - } - return instance; - } - - public static List resolve(String resolver, GenericAttributeResolveRequest request) throws AttributeResolveException { - AttributeResolvable fieldResolver = getAttributeResolver(resolver); - return fieldResolver.resolve(request); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/BadAttributeResolveRequestException.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/BadAttributeResolveRequestException.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/BadAttributeResolveRequestException.java deleted file mode 100644 index 47b26bf..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/BadAttributeResolveRequestException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert.resolver; - -public class BadAttributeResolveRequestException extends Exception { - public BadAttributeResolveRequestException(Exception ex){ - super(ex); - } - - public BadAttributeResolveRequestException(String msg){ - super(msg); - } - - public BadAttributeResolveRequestException(String msg, Exception ex){ - super(msg, ex); - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/GenericAttributeResolveRequest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/GenericAttributeResolveRequest.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/GenericAttributeResolveRequest.java deleted file mode 100644 index ca561e0..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/GenericAttributeResolveRequest.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert.resolver; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * @since 6/16/15 - */ -public class GenericAttributeResolveRequest { - /** - * @param query whatever is in input box of attribute - * @param site which site this policy belongs to - */ - @JsonCreator - public GenericAttributeResolveRequest(@JsonProperty("query") String query, @JsonProperty("site") String site){ - this.query = query; - this.site = site; - } - - public String getQuery() { - return query; - } - - public void setQuery(String query) { - this.query = query; - } - - public String getSite() { - return site; - } - - public void setSite(String site) { - this.site = site; - } - - private String site; - private String query; -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/impl/BooleanAttributeResolver.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/impl/BooleanAttributeResolver.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/impl/BooleanAttributeResolver.java deleted file mode 100644 index 7a4a7c5..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/impl/BooleanAttributeResolver.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert.resolver.impl; - -import eagle.service.alert.resolver.AttributeResolveException; -import eagle.service.alert.resolver.GenericAttributeResolveRequest; -import eagle.service.alert.resolver.AttributeResolvable; - -import java.util.Arrays; -import java.util.List; - -/** - * @since 6/16/15 - */ -public class BooleanAttributeResolver implements AttributeResolvable<GenericAttributeResolveRequest,String> { - @Override - public List<String> resolve(GenericAttributeResolveRequest request) throws AttributeResolveException { - return Arrays.asList("true", "false"); - } - - @Override - public void validateRequest(GenericAttributeResolveRequest request){ - } - - @Override - public Class<GenericAttributeResolveRequest> getRequestClass() { - return GenericAttributeResolveRequest.class; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/impl/EntityAttributeResolver.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/impl/EntityAttributeResolver.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/impl/EntityAttributeResolver.java deleted file mode 100644 index 1d288e2..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/eagle/service/alert/resolver/impl/EntityAttributeResolver.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.service.alert.resolver.impl; - -import eagle.log.entity.GenericServiceAPIResponseEntity; -import eagle.log.base.taggedlog.TaggedLogAPIEntity; -import eagle.log.entity.meta.EntityDefinition; -import eagle.log.entity.meta.EntityDefinitionManager; -import eagle.service.alert.resolver.AttributeResolvable; -import eagle.service.alert.resolver.AttributeResolveException; -import eagle.service.alert.resolver.BadAttributeResolveRequestException; -import eagle.service.alert.resolver.GenericAttributeResolveRequest; -import eagle.service.generic.GenericEntityServiceResource; -import eagle.common.DateTimeUtil; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.annotation.JsonProperty; -import org.apache.commons.lang3.StringUtils; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * @since 6/16/15 - */ -public class EntityAttributeResolver implements AttributeResolvable<EntityAttributeResolver.EntityAttributeResolveRequest,String> { - - private final static GenericEntityServiceResource entityServiceResource = new GenericEntityServiceResource(); - - @Override - public List<String> resolve(EntityAttributeResolveRequest request) throws AttributeResolveException { - if(request.getFieldName()==null){ - throw new AttributeResolveException("fieldName is required"); - } - String attributeName = request.getFieldName(); - EntityDefinition entityDefinition; - try { - if(request.getServiceName()!=null){ - entityDefinition = EntityDefinitionManager.getEntityByServiceName(request.getServiceName()); - }else if (request.getEntityClassName()!=null){ - Class<? extends TaggedLogAPIEntity> entityClass = (Class<? extends TaggedLogAPIEntity>) Class.forName(request.getEntityClassName()); - entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(entityClass); - }else { - throw new AttributeResolveException("At least serviceName or entityClassName is required, but neither found"); - } - } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { - throw new AttributeResolveException(e); - } - List<String> filterCondition = new ArrayList<>(); - if(request.getTags()!=null){ - for(Map.Entry<String,String> tag:request.getTags().entrySet()) { - filterCondition.add("@" + tag.getKey() + " = \"" + tag.getValue() + "\""); - } - } - if(request.getQuery() != null) { - filterCondition.add("@" + attributeName + "~= \".*" + request.getQuery()+".*\""); - } - String query = entityDefinition.getService() + "[" + StringUtils.join(filterCondition, " AND ") + "]<@" + attributeName + ">{count}"; - return aggregateQuery(query, DateTimeUtil.millisecondsToHumanDateWithSeconds(0), DateTimeUtil.millisecondsToHumanDateWithSeconds(System.currentTimeMillis()),request.getMetricName()); - } - - @Override - public Class<EntityAttributeResolveRequest> getRequestClass() { - return EntityAttributeResolveRequest.class; - } - - @Override - public void validateRequest(EntityAttributeResolver.EntityAttributeResolveRequest request) throws BadAttributeResolveRequestException { - - } - - private List<String> aggregateQuery(String query,String startTime,String endTime,String metricName) throws AttributeResolveException { - List<String> result = new ArrayList<>(); - GenericServiceAPIResponseEntity response = entityServiceResource.search(query, startTime, endTime, Integer.MAX_VALUE, null, false, false, 0, Integer.MAX_VALUE, true, 0, metricName, false); - if(response.isSuccess()){ - List objs = response.getObj(); - for(Object item:objs){ - // TODO: get keys as result - throw new IllegalArgumentException("not implemented yet"); - } - }else{ - throw new AttributeResolveException(response.getException()); - } - return result; - } - - public static class EntityAttributeResolveRequest extends GenericAttributeResolveRequest { - public Map<String, String> getTags() { - return tags; - } - private final Map<String, String> tags; - public String getMetricName() { - return metricName; - } - private final String metricName; - @JsonCreator - public EntityAttributeResolveRequest( - @JsonProperty("query") String query, - @JsonProperty("site") String site, - @JsonProperty("serviceName") String serviceName, - @JsonProperty("entityClassName") String entityClassName, - @JsonProperty("metricName") String metricName, - @JsonProperty("fieldName") String fieldName, - @JsonProperty("tags") Map<String, String> tags - ){ - super(query, site); - this.serviceName = serviceName; - this.entityClassName = entityClassName; - this.fieldName = fieldName; - this.metricName = metricName; - this.tags = tags; - } - - private final String serviceName; - public String getEntityClassName() { - return entityClassName; - } - public String getServiceName() { - return serviceName; - } - public String getFieldName() { - return fieldName; - } - private final String entityClassName; - private final String fieldName; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/AlertPolicyValidateProvider.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/AlertPolicyValidateProvider.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/AlertPolicyValidateProvider.java new file mode 100644 index 0000000..47ddcb9 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/AlertPolicyValidateProvider.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert; + +import java.util.List; + +import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.databind.Module; + +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type", visible=true) +@JsonIgnoreProperties(ignoreUnknown = true) +public abstract class AlertPolicyValidateProvider { + public String type; + + public abstract GenericServiceAPIResponseEntity<String> validate(); + + public abstract String PolicyType(); + + public abstract List<Module> BindingModules(); +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/PolicyValidateResource.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/PolicyValidateResource.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/PolicyValidateResource.java new file mode 100644 index 0000000..e4c19d6 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/PolicyValidateResource.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ServiceLoader; + +import javax.ws.rs.Consumes; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.eagle.dataproc.core.JsonSerDeserUtils; +import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity; +import com.fasterxml.jackson.databind.Module; + +@Path("/policy/validate") +public class PolicyValidateResource { + + public static Logger LOG = LoggerFactory.getLogger(PolicyValidateResource.class); + + @SuppressWarnings({"rawtypes"}) + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public GenericServiceAPIResponseEntity validatePolicy(String policyToValidate) { + ServiceLoader<AlertPolicyValidateProvider> loader = ServiceLoader.load(AlertPolicyValidateProvider.class); + Iterator<AlertPolicyValidateProvider> iter = loader.iterator(); + List<Module> modules = new ArrayList<Module>(); + while(iter.hasNext()) { + AlertPolicyValidateProvider factory = iter.next(); + LOG.info("Supported policy type : " + factory.PolicyType()); + modules.addAll(factory.BindingModules()); + } + AlertPolicyValidateProvider policyValidate = null; + try { + policyValidate = JsonSerDeserUtils.deserialize(policyToValidate, AlertPolicyValidateProvider.class, modules); + } + catch (Exception ex) { + LOG.error("Fail consutructing AlertPolicyValidateProvider ", ex); + } + return policyValidate.validate(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/SiddhiAlertPolicyValidateProvider.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/SiddhiAlertPolicyValidateProvider.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/SiddhiAlertPolicyValidateProvider.java new file mode 100644 index 0000000..7c7d5bc --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/SiddhiAlertPolicyValidateProvider.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.eagle.service.generic.GenericEntityServiceResource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.wso2.siddhi.core.ExecutionPlanRuntime; +import org.wso2.siddhi.core.SiddhiManager; + +import org.apache.eagle.alert.common.AlertConstants; +import org.apache.eagle.alert.entity.AlertStreamSchemaEntity; +import org.apache.eagle.alert.siddhi.AttributeType; +import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity; +import org.apache.eagle.common.DateTimeUtil; +import com.fasterxml.jackson.databind.Module; +import com.fasterxml.jackson.databind.jsontype.NamedType; +import com.fasterxml.jackson.databind.module.SimpleModule; + +public class SiddhiAlertPolicyValidateProvider extends AlertPolicyValidateProvider{ + + public String type; + public List<String> streamNames; + public String policyDefinition; + public static Logger LOG = LoggerFactory.getLogger(PolicyValidateResource.class); + public static final String EXECUTION_PLAN_NAME = "query"; + + @SuppressWarnings({"unchecked"}) + public String getStreamDef(String streamName) { + GenericEntityServiceResource resource = new GenericEntityServiceResource(); + String startTime = "1969-01-01 00:00:00"; + String endTime = DateTimeUtil.millisecondsToHumanDateWithSeconds(Long.MAX_VALUE); + int pageSize = 1000; + String query = AlertConstants.ALERT_STREAM_SCHEMA_SERVICE_ENDPOINT_NAME + "[@streamName=\"" + streamName + "\"]{*}"; + GenericServiceAPIResponseEntity<AlertStreamSchemaEntity> streamResponse = resource.search(query, startTime, endTime, pageSize, null, false, false, 0L, 0, true, 0, null, false); + List<AlertStreamSchemaEntity> list = streamResponse.getObj(); + + Map<String, String> map = new HashMap<String, String>(); + for(AlertStreamSchemaEntity entity : list){ + map.put(entity.getTags().get("attrName"), entity.getAttrType()); + } + StringBuilder sb = new StringBuilder(); + sb.append("dataobj object,"); + for(Map.Entry<String, String> entry : map.entrySet()){ + String attrName = entry.getKey(); + sb.append(attrName); + sb.append(" "); + String attrType = entry.getValue(); + if(attrType.equalsIgnoreCase(AttributeType.STRING.name())){ + sb.append("string"); + }else if(attrType.equalsIgnoreCase(AttributeType.INTEGER.name())){ + sb.append("int"); + }else if(attrType.equalsIgnoreCase(AttributeType.LONG.name())){ + sb.append("long"); + }else if(attrType.equalsIgnoreCase(AttributeType.BOOL.name())){ + sb.append("bool"); + }else{ + LOG.error("AttrType is not recognized, ignore : " + attrType); + } + sb.append(","); + } + if(sb.length() > 0){ + sb.deleteCharAt(sb.length()-1); + } + + String siddhiStreamDefFormat = "define stream " + streamName + " (" + "%s" + ");"; + String streamDef = String.format(siddhiStreamDefFormat, sb.toString()); + return streamDef; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Override + public GenericServiceAPIResponseEntity validate() { + GenericServiceAPIResponseEntity result = new GenericServiceAPIResponseEntity(); + SiddhiManager siddhiManager = new SiddhiManager(); + ExecutionPlanRuntime executionPlanRuntime = null; + try { + String streamDefs = new String(); + for(String streamName : streamNames){ + //String streamDef = SiddhiStreamMetadataUtils.convertToStreamDef(streamName); + //We don't use SiddhiStreamMetadataUtils, for it only consume one dataSource + String streamDef = getStreamDef(streamName); + LOG.info("Siddhi stream definition : " + streamDef); + streamDefs += streamDef; + } + + String executionPlan = streamDefs + " @info(name = '" + EXECUTION_PLAN_NAME + "') " + policyDefinition; + executionPlanRuntime = siddhiManager.createExecutionPlanRuntime(executionPlan); + } + catch (Exception ex) { + result.setSuccess(false); + result.setException(ex); + return result; + } + finally { + if (executionPlanRuntime != null) { + executionPlanRuntime.shutdown(); + } + } + result.setSuccess(true); + return result; + } + + @Override + public String PolicyType() { + return "siddhiCEPEngine"; + } + + @Override + public List<Module> BindingModules() { + Module module = new SimpleModule("policyValidate").registerSubtypes(new NamedType(SiddhiAlertPolicyValidateProvider.class, PolicyType())); + return Arrays.asList(module); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolvable.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolvable.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolvable.java new file mode 100644 index 0000000..ecfd47f --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolvable.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert.resolver; + +import java.util.List; + +/** + * @param <R> + * @param <V> + * @since 6/16/15 + */ +public interface AttributeResolvable<R extends GenericAttributeResolveRequest, V> { + /** + * @param request request type + * @return List<V> + * @throws AttributeResolveException + */ + List<V> resolve(R request) throws AttributeResolveException; + + /** + * validate request + * @throws BadAttributeResolveRequestException + */ + void validateRequest(R request) throws BadAttributeResolveRequestException; + + /** + * @return Class<R> + */ + Class<R> getRequestClass(); +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveException.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveException.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveException.java new file mode 100644 index 0000000..56cd942 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveException.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert.resolver; + +/** + * @since 6/16/15 + */ +public class AttributeResolveException extends Exception { + public AttributeResolveException(String s, Exception e) { super(s,e); } + public AttributeResolveException(Exception e) { super(e); } + public AttributeResolveException(String s) { super(s); } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveResource.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveResource.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveResource.java new file mode 100644 index 0000000..68995d1 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveResource.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert.resolver; + +import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity; +import org.apache.eagle.service.common.EagleExceptionWrapper; +import com.fasterxml.jackson.databind.ObjectMapper; + +import javax.ws.rs.*; +import java.io.InputStream; +import java.util.List; + +/** + * @since 6/17/15 + */ +@Path("/stream") +public class AttributeResolveResource { + @POST + @Path("attributeresolve") + @Consumes({"application/json"}) + @Produces({"application/json"}) + public GenericServiceAPIResponseEntity attributeResolve(InputStream request, + @QueryParam("resolver") String resolver){ + GenericServiceAPIResponseEntity response = new GenericServiceAPIResponseEntity(); + try { + if(resolver == null) throw new AttributeResolveException("resolver is null"); + AttributeResolvable resolvable = AttributeResolverFactory.getAttributeResolver(resolver); + ObjectMapper objectMapper = new ObjectMapper(); + Class<?> resolveRequestClass = resolvable.getRequestClass(); + if(resolveRequestClass == null) throw new AttributeResolveException("Request class is null for resolver "+resolver); + GenericAttributeResolveRequest resolveRequest = (GenericAttributeResolveRequest) objectMapper.readValue(request, resolvable.getRequestClass()); + resolvable.validateRequest(resolveRequest); + List result = resolvable.resolve(resolveRequest); + response.setSuccess(true); + response.setObj(result); + } catch (Exception e) { + response.setSuccess(false); + response.setException(EagleExceptionWrapper.wrap(e)); + return response; + } + return response; + } + + @GET + @Path("attributeresolve") + @Produces({"application/json"}) + public GenericServiceAPIResponseEntity attributeResolver( + @QueryParam("resolver") String resolver, @QueryParam("site") String site, @QueryParam("query") String query){ + GenericServiceAPIResponseEntity response = new GenericServiceAPIResponseEntity(); + try { + if(resolver == null) throw new AttributeResolveException("resolver is null"); + AttributeResolvable resolvable = AttributeResolverFactory.getAttributeResolver(resolver); + Class<?> resolveRequestClass = resolvable.getRequestClass(); + if(resolveRequestClass == null) throw new AttributeResolveException("Request class is null for resolver "+resolver); + GenericAttributeResolveRequest resolveRequest = new GenericAttributeResolveRequest(query,site); + resolvable.validateRequest(resolveRequest); + List result = resolvable.resolve(resolveRequest); + response.setSuccess(true); + response.setObj(result); + } catch (Exception e) { + response.setSuccess(false); + response.setException(EagleExceptionWrapper.wrap(e)); + return response; + } + return response; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveResponse.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveResponse.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveResponse.java new file mode 100644 index 0000000..0ec9cf4 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolveResponse.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert.resolver; + +import java.util.List; + +public class AttributeResolveResponse<V> { + private String exception; + private List<V> values; + + public List<V> getValues() { + return values; + } + + public void setValues(List<V> values) { + this.values = values; + } + + public String getException() { + return exception; + } + + public void setException(String exception) { + this.exception = exception; + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolverFactory.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolverFactory.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolverFactory.java new file mode 100644 index 0000000..4015fb7 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/AttributeResolverFactory.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert.resolver; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** +* @since 6/16/15 +*/ +public final class AttributeResolverFactory { + private final static Map<String,AttributeResolvable> fieldResolvableCache = Collections.synchronizedMap(new HashMap<String,AttributeResolvable>()); + public static AttributeResolvable getAttributeResolver(String fieldResolverName) throws AttributeResolveException { + AttributeResolvable instance; + if(fieldResolvableCache.containsKey(fieldResolverName)){ + instance = fieldResolvableCache.get(fieldResolverName); + } else { + try { + instance = (AttributeResolvable) Class.forName(fieldResolverName).newInstance(); + fieldResolvableCache.put(fieldResolverName, instance); + } catch (ClassNotFoundException e) { + throw new AttributeResolveException("Attribute Resolver in type of "+fieldResolverName+" is not found",e); + } catch (InstantiationException | IllegalAccessException e) { + throw new AttributeResolveException(e); + } + } + return instance; + } + + public static List resolve(String resolver, GenericAttributeResolveRequest request) throws AttributeResolveException { + AttributeResolvable fieldResolver = getAttributeResolver(resolver); + return fieldResolver.resolve(request); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/BadAttributeResolveRequestException.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/BadAttributeResolveRequestException.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/BadAttributeResolveRequestException.java new file mode 100644 index 0000000..5a2d7e6 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/BadAttributeResolveRequestException.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert.resolver; + +public class BadAttributeResolveRequestException extends Exception { + public BadAttributeResolveRequestException(Exception ex){ + super(ex); + } + + public BadAttributeResolveRequestException(String msg){ + super(msg); + } + + public BadAttributeResolveRequestException(String msg, Exception ex){ + super(msg, ex); + } +} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/GenericAttributeResolveRequest.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/GenericAttributeResolveRequest.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/GenericAttributeResolveRequest.java new file mode 100644 index 0000000..97899b7 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/GenericAttributeResolveRequest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert.resolver; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * @since 6/16/15 + */ +public class GenericAttributeResolveRequest { + /** + * @param query whatever is in input box of attribute + * @param site which site this policy belongs to + */ + @JsonCreator + public GenericAttributeResolveRequest(@JsonProperty("query") String query, @JsonProperty("site") String site){ + this.query = query; + this.site = site; + } + + public String getQuery() { + return query; + } + + public void setQuery(String query) { + this.query = query; + } + + public String getSite() { + return site; + } + + public void setSite(String site) { + this.site = site; + } + + private String site; + private String query; +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/impl/BooleanAttributeResolver.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/impl/BooleanAttributeResolver.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/impl/BooleanAttributeResolver.java new file mode 100644 index 0000000..3dc70e1 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/impl/BooleanAttributeResolver.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert.resolver.impl; + +import org.apache.eagle.service.alert.resolver.AttributeResolveException; +import org.apache.eagle.service.alert.resolver.GenericAttributeResolveRequest; +import org.apache.eagle.service.alert.resolver.AttributeResolvable; + +import java.util.Arrays; +import java.util.List; + +/** + * @since 6/16/15 + */ +public class BooleanAttributeResolver implements AttributeResolvable<GenericAttributeResolveRequest,String> { + @Override + public List<String> resolve(GenericAttributeResolveRequest request) throws AttributeResolveException { + return Arrays.asList("true", "false"); + } + + @Override + public void validateRequest(GenericAttributeResolveRequest request){ + } + + @Override + public Class<GenericAttributeResolveRequest> getRequestClass() { + return GenericAttributeResolveRequest.class; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/impl/EntityAttributeResolver.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/impl/EntityAttributeResolver.java b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/impl/EntityAttributeResolver.java new file mode 100644 index 0000000..9758863 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/java/org/apache/eagle/service/alert/resolver/impl/EntityAttributeResolver.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.service.alert.resolver.impl; + +import org.apache.eagle.log.entity.GenericServiceAPIResponseEntity; +import org.apache.eagle.log.base.taggedlog.TaggedLogAPIEntity; +import org.apache.eagle.log.entity.meta.EntityDefinition; +import org.apache.eagle.log.entity.meta.EntityDefinitionManager; +import org.apache.eagle.service.alert.resolver.AttributeResolvable; +import org.apache.eagle.service.alert.resolver.AttributeResolveException; +import org.apache.eagle.service.alert.resolver.BadAttributeResolveRequestException; +import org.apache.eagle.service.alert.resolver.GenericAttributeResolveRequest; +import org.apache.eagle.service.generic.GenericEntityServiceResource; +import org.apache.eagle.common.DateTimeUtil; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +/** + * @since 6/16/15 + */ +public class EntityAttributeResolver implements AttributeResolvable<EntityAttributeResolver.EntityAttributeResolveRequest,String> { + + private final static GenericEntityServiceResource entityServiceResource = new GenericEntityServiceResource(); + + @Override + public List<String> resolve(EntityAttributeResolveRequest request) throws AttributeResolveException { + if(request.getFieldName()==null){ + throw new AttributeResolveException("fieldName is required"); + } + String attributeName = request.getFieldName(); + EntityDefinition entityDefinition; + try { + if(request.getServiceName()!=null){ + entityDefinition = EntityDefinitionManager.getEntityByServiceName(request.getServiceName()); + }else if (request.getEntityClassName()!=null){ + Class<? extends TaggedLogAPIEntity> entityClass = (Class<? extends TaggedLogAPIEntity>) Class.forName(request.getEntityClassName()); + entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(entityClass); + }else { + throw new AttributeResolveException("At least serviceName or entityClassName is required, but neither found"); + } + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { + throw new AttributeResolveException(e); + } + List<String> filterCondition = new ArrayList<>(); + if(request.getTags()!=null){ + for(Map.Entry<String,String> tag:request.getTags().entrySet()) { + filterCondition.add("@" + tag.getKey() + " = \"" + tag.getValue() + "\""); + } + } + if(request.getQuery() != null) { + filterCondition.add("@" + attributeName + "~= \".*" + request.getQuery()+".*\""); + } + String query = entityDefinition.getService() + "[" + StringUtils.join(filterCondition, " AND ") + "]<@" + attributeName + ">{count}"; + return aggregateQuery(query, DateTimeUtil.millisecondsToHumanDateWithSeconds(0), DateTimeUtil.millisecondsToHumanDateWithSeconds(System.currentTimeMillis()),request.getMetricName()); + } + + @Override + public Class<EntityAttributeResolveRequest> getRequestClass() { + return EntityAttributeResolveRequest.class; + } + + @Override + public void validateRequest(EntityAttributeResolver.EntityAttributeResolveRequest request) throws BadAttributeResolveRequestException { + + } + + private List<String> aggregateQuery(String query,String startTime,String endTime,String metricName) throws AttributeResolveException { + List<String> result = new ArrayList<>(); + GenericServiceAPIResponseEntity response = entityServiceResource.search(query, startTime, endTime, Integer.MAX_VALUE, null, false, false, 0, Integer.MAX_VALUE, true, 0, metricName, false); + if(response.isSuccess()){ + List objs = response.getObj(); + for(Object item:objs){ + // TODO: get keys as result + throw new IllegalArgumentException("not implemented yet"); + } + }else{ + throw new AttributeResolveException(response.getException()); + } + return result; + } + + public static class EntityAttributeResolveRequest extends GenericAttributeResolveRequest { + public Map<String, String> getTags() { + return tags; + } + private final Map<String, String> tags; + public String getMetricName() { + return metricName; + } + private final String metricName; + @JsonCreator + public EntityAttributeResolveRequest( + @JsonProperty("query") String query, + @JsonProperty("site") String site, + @JsonProperty("serviceName") String serviceName, + @JsonProperty("entityClassName") String entityClassName, + @JsonProperty("metricName") String metricName, + @JsonProperty("fieldName") String fieldName, + @JsonProperty("tags") Map<String, String> tags + ){ + super(query, site); + this.serviceName = serviceName; + this.entityClassName = entityClassName; + this.fieldName = fieldName; + this.metricName = metricName; + this.tags = tags; + } + + private final String serviceName; + public String getEntityClassName() { + return entityClassName; + } + public String getServiceName() { + return serviceName; + } + public String getFieldName() { + return fieldName; + } + private final String entityClassName; + private final String fieldName; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/resources/META-INF/services/eagle.service.alert.AlertPolicyValidateProvider ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/resources/META-INF/services/eagle.service.alert.AlertPolicyValidateProvider b/eagle-core/eagle-alert/eagle-alert-service/src/main/resources/META-INF/services/eagle.service.alert.AlertPolicyValidateProvider deleted file mode 100644 index be6e2c7..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/main/resources/META-INF/services/eagle.service.alert.AlertPolicyValidateProvider +++ /dev/null @@ -1 +0,0 @@ -eagle.service.alert.SiddhiAlertPolicyValidateProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/main/resources/META-INF/services/org.apache.eagle.service.alert.AlertPolicyValidateProvider ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/main/resources/META-INF/services/org.apache.eagle.service.alert.AlertPolicyValidateProvider b/eagle-core/eagle-alert/eagle-alert-service/src/main/resources/META-INF/services/org.apache.eagle.service.alert.AlertPolicyValidateProvider new file mode 100644 index 0000000..1f92d71 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/main/resources/META-INF/services/org.apache.eagle.service.alert.AlertPolicyValidateProvider @@ -0,0 +1 @@ +org.apache.eagle.service.alert.SiddhiAlertPolicyValidateProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/test/resources/META-INF/services/eagle.service.alert.AlertPolicyValidateProvider ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/test/resources/META-INF/services/eagle.service.alert.AlertPolicyValidateProvider b/eagle-core/eagle-alert/eagle-alert-service/src/test/resources/META-INF/services/eagle.service.alert.AlertPolicyValidateProvider deleted file mode 100644 index be6e2c7..0000000 --- a/eagle-core/eagle-alert/eagle-alert-service/src/test/resources/META-INF/services/eagle.service.alert.AlertPolicyValidateProvider +++ /dev/null @@ -1 +0,0 @@ -eagle.service.alert.SiddhiAlertPolicyValidateProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-alert/eagle-alert-service/src/test/resources/META-INF/services/org.apache.eagle.service.alert.AlertPolicyValidateProvider ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-alert/eagle-alert-service/src/test/resources/META-INF/services/org.apache.eagle.service.alert.AlertPolicyValidateProvider b/eagle-core/eagle-alert/eagle-alert-service/src/test/resources/META-INF/services/org.apache.eagle.service.alert.AlertPolicyValidateProvider new file mode 100644 index 0000000..1f92d71 --- /dev/null +++ b/eagle-core/eagle-alert/eagle-alert-service/src/test/resources/META-INF/services/org.apache.eagle.service.alert.AlertPolicyValidateProvider @@ -0,0 +1 @@ +org.apache.eagle.service.alert.SiddhiAlertPolicyValidateProvider \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/DefaultJobPartitionerImpl.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/DefaultJobPartitionerImpl.java b/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/DefaultJobPartitionerImpl.java deleted file mode 100644 index b9cf642..0000000 --- a/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/DefaultJobPartitionerImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.job; - -public class DefaultJobPartitionerImpl implements JobPartitioner { - @Override - public int partition(int numTotalParts, String key) { - int hash = key.hashCode(); - hash = Math.abs(hash); - return hash % numTotalParts; - } -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/JobFilter.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/JobFilter.java b/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/JobFilter.java deleted file mode 100644 index 96e6b0c..0000000 --- a/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/JobFilter.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.job; - -public interface JobFilter { - public boolean accept(String key); -} http://git-wip-us.apache.org/repos/asf/incubator-eagle/blob/afe86834/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/JobFilterByPartition.java ---------------------------------------------------------------------- diff --git a/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/JobFilterByPartition.java b/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/JobFilterByPartition.java deleted file mode 100644 index 29a73fe..0000000 --- a/eagle-core/eagle-data-process/eagle-job-common/src/main/java/eagle/job/JobFilterByPartition.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package eagle.job; - -public class JobFilterByPartition implements JobFilter { - private JobPartitioner partitioner; - private int numTotalPartitions; - private int partitionId; - - public JobFilterByPartition(JobPartitioner partitioner, int numTotalPartitions, int partitionId){ - this.partitioner = partitioner; - this.numTotalPartitions = numTotalPartitions; - this.partitionId = partitionId; - } - - @Override - public boolean accept(String key) { - int part = partitioner.partition(numTotalPartitions, key); - if(part == partitionId) - return true; - return false; - } -}