You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apex.apache.org by th...@apache.org on 2017/03/07 06:58:33 UTC
[28/30] apex-malhar git commit: Renamed demos to examples. Packages
and artifactid names are changed as suggested.
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/CreditCardAmountSamplerOperator.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/CreditCardAmountSamplerOperator.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/CreditCardAmountSamplerOperator.java
deleted file mode 100644
index a232fd4..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/CreditCardAmountSamplerOperator.java
+++ /dev/null
@@ -1,206 +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 com.datatorrent.demos.frauddetect;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.codehaus.jackson.JsonFactory;
-import org.codehaus.jackson.map.ObjectMapper;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.commons.lang.mutable.MutableLong;
-
-import com.datatorrent.api.DefaultInputPort;
-import com.datatorrent.api.DefaultOutputPort;
-import com.datatorrent.common.util.BaseOperator;
-import com.datatorrent.demos.frauddetect.util.JsonUtils;
-import com.datatorrent.lib.util.KeyValPair;
-
-/**
- * An operator to alert in case a transaction of a small lowAmount is followed by a transaction which is significantly larger for a given credit card number.
- * This is done for each transaction. This also means that this happens for each individual credit card.
- * It accepts merchant transaction object and for each CC listed in the transaction(s), checks for the transaction amounts. An alert is raised if the transaction
- * lowAmount is significantly > the lowest amt in this window.
- *
- * @since 0.9.0
- */
-public class CreditCardAmountSamplerOperator extends BaseOperator
-{
- private final transient JsonFactory jsonFactory = new JsonFactory();
- private final transient ObjectMapper mapper = new ObjectMapper(jsonFactory);
- private static final Logger logger = LoggerFactory.getLogger(Application.class);
- // Factor to be applied to existing lowAmount to flag potential alerts.
- private double threshold = 9500;
- private Map<String, CreditCardInfo> ccTxnMap = new HashMap<String, CreditCardInfo>();
- //private Map<String, MutableLong> ccQueryTxnMap = new HashMap<String, MutableLong>();
- private List<CreditCardAlertData> alerts = new ArrayList<CreditCardAlertData>();
- //private List<CreditCardAlertData> userAlerts = new ArrayList<CreditCardAlertData>();
- private static final String ALERT_MSG =
- "Potential fraudulent CC transactions (small one USD %d followed by large USD %d) performed using credit card: %s";
- public final transient DefaultOutputPort<String> ccAlertOutputPort = new DefaultOutputPort<String>();
- /*
- public final transient DefaultOutputPort<Map<String, Object>> ccUserAlertOutputPort = new DefaultOutputPort<Map<String, Object>>();
- */
- public final transient DefaultOutputPort<Map<String, Object>> ccAlertNotificationPort = new DefaultOutputPort<Map<String, Object>>();
-
- public double getThreshold()
- {
- return threshold;
- }
-
- public void setThreshold(double threshold)
- {
- this.threshold = threshold;
- }
-
- private void processTuple(KeyValPair<MerchantKey, CreditCardData> tuple, Map<String, CreditCardInfo> txMap)
- {
- String fullCcNum = tuple.getValue().fullCcNum;
- long ccAmount = tuple.getValue().amount;
- MerchantKey key = tuple.getKey();
-
- CreditCardInfo cardInfo = txMap.get(fullCcNum);
-
- if (cardInfo != null) {
- long currentSmallValue = cardInfo.lowAmount.longValue();
- if (ccAmount < currentSmallValue) {
- cardInfo.lowAmount.setValue(ccAmount);
- cardInfo.time = key.time;
- } else if (ccAmount > (currentSmallValue + threshold)) {
- // If the transaction lowAmount is > 70% of the min. lowAmount, send an alert.
-
- CreditCardAlertData data = new CreditCardAlertData();
-
- data.merchantId = key.merchantId;
- data.terminalId = key.terminalId == null ? 0 : key.terminalId;
- data.zipCode = key.zipCode;
- data.merchantType = key.merchantType;
- data.fullCcNum = fullCcNum;
- data.small = currentSmallValue;
- data.large = ccAmount;
- data.threshold = threshold;
- data.userGenerated = key.userGenerated;
- data.time = System.currentTimeMillis();
-
- alerts.add(data);
-
- /*
- if (userGenerated){
- userAlerts.add(data);
- }
- */
- ccAlertNotificationPort.emit(getOutputData(data));
-
- // Any high value transaction after a low value transaction with difference greater than threshold
- // will trigger the alert. Not resetting the low value also helps in a system generated transaction
- // alert not resetting the low value from a user generated transaction
- //txMap.remove(fullCcNum);
- }
- } else {
- cardInfo = new CreditCardInfo();
- cardInfo.lowAmount.setValue(ccAmount);
- cardInfo.time = key.time;
- txMap.put(fullCcNum, cardInfo);
- }
- }
-
- public transient DefaultInputPort<KeyValPair<MerchantKey, CreditCardData>> inputPort =
- new DefaultInputPort<KeyValPair<MerchantKey, CreditCardData>>()
- {
- //
- // This function checks if a CC entry exists.
- // If so, it checks whether the current transaction is for an lowAmount lesser than the one stored in the hashmap. If so, this becomes the min. transaction lowAmount.
- // If the lowAmount is > 70% of the existing lowAmount in the hash map, raise an alert.
- //
- @Override
- public void process(KeyValPair<MerchantKey, CreditCardData> tuple)
- {
-
- processTuple(tuple, ccTxnMap);
-
- }
-
- };
-
- @Override
- public void endWindow()
- {
-
- for (CreditCardAlertData data : alerts) {
- try {
- ccAlertOutputPort.emit(JsonUtils.toJson(data));
- } catch (IOException e) {
- logger.warn("Exception while converting object to JSON", e);
- }
- }
-
- //for (CreditCardAlertData data: userAlerts) {
- /*for (CreditCardAlertData data: alerts) {
- ccAlertNotificationPort.emit(getOutputData(data));
- }*/
-
- long ctime = System.currentTimeMillis();
- Iterator<Map.Entry<String, CreditCardInfo>> iterator = ccTxnMap.entrySet().iterator();
- while (iterator.hasNext()) {
- Map.Entry<String, CreditCardInfo> entry = iterator.next();
- long time = entry.getValue().time;
- if ((ctime - time) > 60000) {
- iterator.remove();
- }
- }
-
- //ccTxnMap.clear();
- alerts.clear();
-
- //ccQueryTxnMap.clear();
- //userAlerts.clear();
- }
-
- private static class CreditCardInfo
- {
- MutableLong lowAmount = new MutableLong();
- Long time;
- }
-
- private Map<String, Object> getOutputData(CreditCardAlertData data)
- {
- Map<String, Object> output = new HashMap<String, Object>();
- output.put("message", String.format(ALERT_MSG, data.small, data.large, data.fullCcNum));
- output.put("alertType", "smallThenLarge");
- output.put("userGenerated", "" + data.userGenerated);
- output.put("alertData", data);
-
- try {
- String str = mapper.writeValueAsString(output);
- logger.debug("Alert generated: " + str + " userGenerated: " + data.userGenerated);
- } catch (Exception exc) {
- //ignore
- }
-
- return output;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/CreditCardData.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/CreditCardData.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/CreditCardData.java
deleted file mode 100644
index 68a2cf7..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/CreditCardData.java
+++ /dev/null
@@ -1,35 +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 com.datatorrent.demos.frauddetect;
-
-/**
- * Credit Card Data
- *
- * @since 0.9.0
- */
-public class CreditCardData
-{
- public String fullCcNum;
- public long amount;
-
- public CreditCardData()
- {
- }
-
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantKey.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantKey.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantKey.java
deleted file mode 100644
index a6204c9..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantKey.java
+++ /dev/null
@@ -1,128 +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 com.datatorrent.demos.frauddetect;
-
-
-import java.io.Serializable;
-
-/**
- * A time-based key for merchant data.
- *
- * @since 0.9.0
- */
-public class MerchantKey implements Serializable
-{
- public String merchantId;
- public Integer terminalId;
- public Integer zipCode;
- public String country;
- public MerchantTransaction.MerchantType merchantType;
- public Long time;
- public boolean userGenerated;
-
- public MerchantKey()
- {
- }
-
- @Override
- public int hashCode()
- {
- int key = 0;
- if (merchantId != null) {
- key |= (1 << 1);
- key |= (merchantId.hashCode());
- }
- if (terminalId != null) {
- key |= (1 << 2);
- key |= (terminalId << 2);
- }
- if (zipCode != null) {
- key |= (1 << 3);
- key |= (zipCode << 3);
- }
- if (country != null) {
- key |= (1 << 4);
- key |= (country.hashCode());
- }
- if (merchantType != null) {
- key |= (1 << 5);
- key |= (merchantType.hashCode());
- }
- return key;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (!(obj instanceof MerchantKey)) {
- return false;
- }
- MerchantKey mkey = (MerchantKey)obj;
- return checkStringEqual(this.merchantId, mkey.merchantId)
- && checkIntEqual(this.terminalId, mkey.terminalId)
- && checkIntEqual(this.zipCode, mkey.zipCode)
- && checkStringEqual(this.country, mkey.country)
- && checkIntEqual(this.merchantType.ordinal(), mkey.merchantType.ordinal());
- }
-
- private boolean checkIntEqual(Integer a, Integer b)
- {
- if ((a == null) && (b == null)) {
- return true;
- }
- if ((a != null) && (b != null) && a.intValue() == b.intValue()) {
- return true;
- }
- return false;
- }
-
- private boolean checkStringEqual(String a, String b)
- {
- if ((a == null) && (b == null)) {
- return true;
- }
- if ((a != null) && a.equals(b)) {
- return true;
- }
- return false;
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- if (merchantId != null) {
- sb.append("|1:").append(merchantId);
- }
- if (terminalId != null) {
- sb.append("|2:").append(terminalId);
- }
- if (zipCode != null) {
- sb.append("|3:").append(zipCode);
- }
- if (country != null) {
- sb.append("|4:").append(country);
- }
- if (merchantType != null) {
- sb.append("|5:").append(merchantType);
- }
- return sb.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantQueryInputHandler.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantQueryInputHandler.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantQueryInputHandler.java
deleted file mode 100644
index c57f86d..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantQueryInputHandler.java
+++ /dev/null
@@ -1,69 +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 com.datatorrent.demos.frauddetect;
-
-import java.util.Map;
-
-/**
- * Common utility class that can be used by all other operators to handle user input
- * captured from the Web socket input port.
- *
- * @since 0.9.0
- */
-public class MerchantQueryInputHandler
-{
- public static final String KEY_DATA = "data";
- public static final String KEY_MERCHANT_ID = "merchantId";
- public static final String KEY_TERMINAL_ID = "terminalId";
- public static final String KEY_ZIP_CODE = "zipCode";
-
- public static MerchantKey process(Map<String, Object> tuple)
- {
- String merchantId = null;
- Integer terminalId = null;
- Integer zipCode = null;
-
- // ignoring other top-level attributes.
- Map<String, Object> data = (Map<String, Object>)tuple.get(KEY_DATA);
- if (data.get(KEY_MERCHANT_ID) != null) {
- merchantId = (String)data.get(KEY_MERCHANT_ID);
- }
- if (data.get(KEY_TERMINAL_ID) != null) {
- terminalId = (Integer)data.get(KEY_TERMINAL_ID);
- }
- if (data.get(KEY_ZIP_CODE) != null) {
- zipCode = (Integer)data.get(KEY_ZIP_CODE);
- }
-
- MerchantKey key = new MerchantKey();
- key.merchantId = merchantId;
- key.terminalId = terminalId;
- key.zipCode = zipCode;
- key.country = "USA";
- if (merchantId != null) {
- key.merchantType = key.merchantId.equalsIgnoreCase(MerchantTransactionGenerator.merchantIds[2])
- || key.merchantId.equalsIgnoreCase(MerchantTransactionGenerator.merchantIds[3])
- ? MerchantTransaction.MerchantType.INTERNET
- : MerchantTransaction.MerchantType.BRICK_AND_MORTAR;
- }
- return key;
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransaction.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransaction.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransaction.java
deleted file mode 100644
index 75e279c..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransaction.java
+++ /dev/null
@@ -1,202 +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 com.datatorrent.demos.frauddetect;
-
-import java.io.Serializable;
-
-/**
- * POJO for BIN Alert related data.
- *
- * @since 0.9.0
- */
-public class MerchantTransaction implements Serializable
-{
- public enum MerchantType
- {
- UNDEFINED, BRICK_AND_MORTAR, INTERNET
- }
-
- public enum TransactionType
- {
- UNDEFINED, POS
- }
-
- public String ccNum;
- public String bankIdNum;
- public String fullCcNum;
- public Long amount;
- public String merchantId;
- public Integer terminalId;
- public Integer zipCode;
- public String country;
- public MerchantType merchantType = MerchantType.UNDEFINED;
- public TransactionType transactionType = TransactionType.UNDEFINED;
- public Long time;
- public boolean userGenerated;
-
- public MerchantTransaction()
- {
- }
-
- @Override
- public int hashCode()
- {
- int key = 0;
- if (ccNum != null) {
- key |= (1 << 1);
- key |= (ccNum.hashCode());
- }
- if (bankIdNum != null) {
- key |= (1 << 2);
- key |= (bankIdNum.hashCode());
- }
- if (amount != null) {
- key |= (1 << 6);
- key |= (amount << 4);
- }
- if (merchantId != null) {
- key |= (1 << 3);
- key |= (merchantId.hashCode());
- }
- if (terminalId != null) {
- key |= (1 << 4);
- key |= (terminalId << 2);
- }
- if (zipCode != null) {
- key |= (1 << 5);
- key |= (zipCode << 3);
- }
- if (country != null) {
- key |= (1 << 7);
- key |= (country.hashCode());
- }
- if (merchantType != null) {
- key |= (1 << 8);
- key |= (merchantType.hashCode());
- }
- if (transactionType != null) {
- key |= (1 << 9);
- key |= (transactionType.hashCode());
- }
- if (fullCcNum != null) {
- key |= (1 << 10);
- key |= (fullCcNum.hashCode());
- }
- if (time != null) {
- key |= (1 << 11);
- key |= (time << 2);
- }
-
- return key;
- }
-
- @Override
- public boolean equals(Object obj)
- {
- if (!(obj instanceof MerchantTransaction)) {
- return false;
- }
- MerchantTransaction mtx = (MerchantTransaction)obj;
- return checkStringEqual(this.ccNum, mtx.ccNum)
- && checkStringEqual(this.bankIdNum, mtx.bankIdNum)
- && checkLongEqual(this.amount, mtx.amount)
- && checkStringEqual(this.merchantId, mtx.merchantId)
- && checkIntEqual(this.terminalId, mtx.terminalId)
- && checkIntEqual(this.zipCode, mtx.zipCode)
- && checkStringEqual(this.country, mtx.country)
- && checkIntEqual(this.merchantType.ordinal(), mtx.merchantType.ordinal())
- && checkIntEqual(this.transactionType.ordinal(), mtx.transactionType.ordinal())
- && checkStringEqual(this.fullCcNum, mtx.fullCcNum)
- && checkLongEqual(this.time, mtx.time);
- }
-
- private boolean checkIntEqual(Integer a, Integer b)
- {
- if ((a == null) && (b == null)) {
- return true;
- }
- if ((a != null) && (b != null) && a.intValue() == b.intValue()) {
- return true;
- }
- return false;
- }
-
- private boolean checkLongEqual(Long a, Long b)
- {
- if ((a == null) && (b == null)) {
- return true;
- }
- if ((a != null) && (b != null) && a.longValue() == b.longValue()) {
- return true;
- }
- return false;
- }
-
- private boolean checkStringEqual(String a, String b)
- {
- if ((a == null) && (b == null)) {
- return true;
- }
- if ((a != null) && a.equals(b)) {
- return true;
- }
- return false;
- }
-
- @Override
- public String toString()
- {
- StringBuilder sb = new StringBuilder();
- if (ccNum != null) {
- sb.append("|0:").append(ccNum);
- }
- if (bankIdNum != null) {
- sb.append("|1:").append(bankIdNum);
- }
- if (fullCcNum != null) {
- sb.append("|2:").append(fullCcNum);
- }
- if (amount != null) {
- sb.append("|3:").append(amount);
- }
- if (merchantId != null) {
- sb.append("|4:").append(merchantId);
- }
- if (terminalId != null) {
- sb.append("|5:").append(terminalId);
- }
- if (zipCode != null) {
- sb.append("|6:").append(zipCode);
- }
- if (country != null) {
- sb.append("|7:").append(country);
- }
- if (merchantType != null) {
- sb.append("|8:").append(merchantType);
- }
- if (transactionType != null) {
- sb.append("|9:").append(transactionType);
- }
- if (time != null) {
- sb.append("|10:").append(time);
- }
- return sb.toString();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionBucketOperator.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionBucketOperator.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionBucketOperator.java
deleted file mode 100644
index 243137d..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionBucketOperator.java
+++ /dev/null
@@ -1,148 +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 com.datatorrent.demos.frauddetect;
-
-import java.text.DecimalFormat;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.commons.lang.mutable.MutableDouble;
-import org.apache.commons.lang.mutable.MutableLong;
-
-import com.datatorrent.api.DefaultInputPort;
-import com.datatorrent.api.DefaultOutputPort;
-import com.datatorrent.common.util.BaseOperator;
-import com.datatorrent.lib.util.KeyValPair;
-
-/**
- * A bucket-like operator to accept merchant transaction object and dissipate the
- * transaction amount to the further downstream operator for calculating min, max and std-deviation.
- *
- * @since 0.9.0
- */
-public class MerchantTransactionBucketOperator extends BaseOperator
-{
- private static final Logger logger = LoggerFactory.getLogger(MerchantTransactionBucketOperator.class);
- /*
- public final transient DefaultOutputPort<KeyValPair<MerchantKey, String>> binOutputPort =
- new DefaultOutputPort<KeyValPair<MerchantKey, String>>();
- */
- public final transient DefaultOutputPort<KeyValPair<KeyValPair<MerchantKey, String>, Integer>> binCountOutputPort =
- new DefaultOutputPort<KeyValPair<KeyValPair<MerchantKey, String>, Integer>>();
- public final transient DefaultOutputPort<KeyValPair<MerchantKey, Long>> txOutputPort =
- new DefaultOutputPort<KeyValPair<MerchantKey, Long>>();
- public final transient DefaultOutputPort<KeyValPair<MerchantKey, CreditCardData>> ccAlertOutputPort =
- new DefaultOutputPort<KeyValPair<MerchantKey, CreditCardData>>();
- public final transient DefaultOutputPort<Map<String, Object>> summaryTxnOutputPort =
- new DefaultOutputPort<Map<String, Object>>();
- private MutableLong totalTxns = new MutableLong(0);
- private MutableLong txnsInLastSecond = new MutableLong(0);
- private MutableDouble amtInLastSecond = new MutableDouble(0);
- private transient DecimalFormat amtFormatter = new DecimalFormat("#.##");
- public transient DefaultInputPort<MerchantTransaction> inputPort = new DefaultInputPort<MerchantTransaction>()
- {
- @Override
- public void process(MerchantTransaction tuple)
- {
- processTuple(tuple);
- }
-
- };
- public transient DefaultInputPort<MerchantTransaction> txUserInputPort = new DefaultInputPort<MerchantTransaction>()
- {
- @Override
- public void process(MerchantTransaction tuple)
- {
- processTuple(tuple);
- }
-
- };
-
- public void endWindow()
- {
- Map<String, Object> summary = new HashMap<String, Object>();
- double avg;
- if (txnsInLastSecond.longValue() == 0) {
- avg = 0;
- } else {
- avg = amtInLastSecond.doubleValue() / txnsInLastSecond.longValue();
- }
- summary.put("totalTxns", totalTxns);
- summary.put("txnsInLastSecond", txnsInLastSecond);
- summary.put("amtInLastSecond", amtFormatter.format(amtInLastSecond));
- summary.put("avgAmtInLastSecond", amtFormatter.format(avg));
- summaryTxnOutputPort.emit(summary);
- txnsInLastSecond.setValue(0);
- amtInLastSecond.setValue(0);
- }
-
- private void processTuple(MerchantTransaction tuple)
- {
- emitBankIdNumTuple(tuple, binCountOutputPort);
- emitMerchantKeyTuple(tuple, txOutputPort);
- emitCreditCardKeyTuple(tuple, ccAlertOutputPort);
- totalTxns.increment();
- txnsInLastSecond.increment();
- amtInLastSecond.add(tuple.amount);
- }
-
- private void emitMerchantKeyTuple(MerchantTransaction tuple, DefaultOutputPort<KeyValPair<MerchantKey, Long>> outputPort)
- {
- MerchantKey key = getMerchantKey(tuple);
- KeyValPair<MerchantKey, Long> keyValPair = new KeyValPair<MerchantKey, Long>(key, tuple.amount);
- outputPort.emit(keyValPair);
- }
-
- //private void emitBankIdNumTuple(MerchantTransaction tuple, DefaultOutputPort<KeyValPair<MerchantKey, String>> outputPort)
- private void emitBankIdNumTuple(MerchantTransaction tuple, DefaultOutputPort<KeyValPair<KeyValPair<MerchantKey, String>, Integer>> outputPort)
- {
- MerchantKey key = getMerchantKey(tuple);
- KeyValPair<MerchantKey, String> keyValPair = new KeyValPair<MerchantKey, String>(key, tuple.bankIdNum);
- outputPort.emit(new KeyValPair<KeyValPair<MerchantKey, String>, Integer>(keyValPair, 1));
- }
-
- private void emitCreditCardKeyTuple(MerchantTransaction tuple, DefaultOutputPort<KeyValPair<MerchantKey, CreditCardData>> outputPort)
- {
- MerchantKey key = getMerchantKey(tuple);
-
- CreditCardData data = new CreditCardData();
- data.fullCcNum = tuple.fullCcNum;
- data.amount = tuple.amount;
-
- KeyValPair<MerchantKey, CreditCardData> keyValPair = new KeyValPair<MerchantKey, CreditCardData>(key, data);
- outputPort.emit(keyValPair);
- }
-
- private MerchantKey getMerchantKey(MerchantTransaction tuple)
- {
- MerchantKey key = new MerchantKey();
- key.merchantId = tuple.merchantId;
- key.terminalId = tuple.terminalId;
- key.zipCode = tuple.zipCode;
- key.country = tuple.country;
- key.merchantType = tuple.merchantType;
- key.userGenerated = tuple.userGenerated;
- key.time = tuple.time;
- return key;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionGenerator.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionGenerator.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionGenerator.java
deleted file mode 100644
index 49b61aa..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionGenerator.java
+++ /dev/null
@@ -1,210 +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 com.datatorrent.demos.frauddetect;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.datatorrent.api.Context;
-import com.datatorrent.api.DefaultOutputPort;
-import com.datatorrent.api.InputOperator;
-
-import com.datatorrent.common.util.BaseOperator;
-import com.datatorrent.demos.frauddetect.util.JsonUtils;
-
-/**
- * Information tuple generator with randomness.
- *
- * @since 0.9.0
- */
-public class MerchantTransactionGenerator extends BaseOperator implements InputOperator
-{
- private final Random randomNum = new Random();
- public static final int[] zipCodes = {94086, 94087, 94088, 94089, 94090, 94091, 94092, 94093};
- public static final String[] merchantIds = {"Wal-Mart", "Target", "Amazon", "Apple", "Sears", "Macys", "JCPenny", "Levis"};
-// public static final String bankIdNums[] = { "1111 1111 1111", "2222 2222 2222", "3333 3333 3333", "4444 4444 4444", "5555 5555 5555", "6666 6666 6666", "7777 7777 7777", "8888 8888 8888"};
-// public static final String ccNums[] = { "0001", "0002", "0003", "0004", "0005", "0006", "0007", "0008"};
-// public static final String bankIdNums[] = { "1111 1111 1111", "2222 2222 2222", "3333 3333 3333", "4444 4444 4444"};
-// public static final String ccNums[] = { "0001", "0002", "0003", "0004"};
-// public static final int zipCodes[] = { 94086, 94087, 94088, 94089, 94090};
-// public static final String merchantIds[] = { "Wal-Mart", "Target", "Amazon", "Apple"};
-// private int bankIdNumMin = 0;
-// private int bankIdNumMax = bankIdNums.length - 1;
-// private int ccMin = 0;
-// private int ccMax = ccNums.length - 1;
- private int amountMin = 1;
- private int amountMax = 400;
- private int merchantIdMin = 0;
- private int merchantIdMax = merchantIds.length - 1;
- private int terminalIdMin = 1;
- private int terminalIdMax = 8;
- private int zipMin = 0;
- private int zipMax = zipCodes.length - 1;
- private int tupleBlastSize = 2000;
- private boolean stopGeneration = false;
-
- @Override
- public void setup(Context.OperatorContext context)
- {
- super.setup(context);
- }
-
- public transient DefaultOutputPort<MerchantTransaction> txOutputPort =
- new DefaultOutputPort<MerchantTransaction>();
- public transient DefaultOutputPort<String> txDataOutputPort =
- new DefaultOutputPort<String>();
-
- @Override
- public void emitTuples()
- {
- int count = 0;
- List<MerchantTransaction> txList = new ArrayList();
-
- while (!stopGeneration && count < getTupleBlastSize()) {
-
- String bankIdNum = genBankIdNum();
- String ccNum = genCC();
- int merchant = genMerchantId();
- int terminal = genTerminalId();
- int zip = genZip();
-
- long amount = genAmount();
-
-// int bankIdNum = 1;
-// int ccNum = 2;
-// long amount = 5000;
-// int merchant = 3;
-// int terminal = 4;
-// int zip = 0;
-
- MerchantTransaction tx = new MerchantTransaction();
- tx.bankIdNum = bankIdNum;
- tx.ccNum = ccNum;
- tx.fullCcNum = tx.bankIdNum + " " + tx.ccNum;
- tx.amount = amount;
- tx.merchantId = merchantIds[merchant];
-
- // its INTERNET merchant
- tx.merchantType = merchant == 2 || merchant == 3
- ? MerchantTransaction.MerchantType.INTERNET
- : MerchantTransaction.MerchantType.BRICK_AND_MORTAR;
-
- tx.transactionType = MerchantTransaction.TransactionType.POS;
-
- // set terminal only for a BRICK_AND_MORTAR merchant
- if (merchant != 2 && merchant != 3) {
- tx.terminalId = terminal;
- }
- tx.zipCode = zipCodes[zip];
- tx.country = "USA";
- tx.time = System.currentTimeMillis();
-
- tx.userGenerated = false;
-
- txOutputPort.emit(tx);
-
- txList.add(tx);
-
- count++;
- }
- for (MerchantTransaction txData : txList) {
- try {
- txDataOutputPort.emit(JsonUtils.toJson(txData));
- } catch (IOException e) {
- logger.warn("Exception while converting object to JSON", e);
- }
- }
- txList.clear();
-
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- }
-
- public String genBankIdNum()
- {
- // Bank ID will be between 1000 0000 and 3500 0000 (25 BINs)
- int base = randomNum.nextInt(100) + 100;
- return base + "0 0000";
- }
-
- public String genCC()
- {
- // CC will be 1000 0000 to 1400 0000 (400,000 cards per BIN)
- int base = (randomNum.nextInt(100000) + 10000000);
- String baseString = Integer.toString(base);
- return baseString.substring(0, 4) + " " + baseString.substring(4);
- }
-
- public int genAmount()
- {
- int lowRange = 50;
- int range = amountMax - amountMin + randomNum.nextInt(lowRange);
- return amountMin + randomNum.nextInt(range);
- }
-
- public int genMerchantId()
- {
- int range = merchantIdMax - merchantIdMin + 1;
- return merchantIdMin + randomNum.nextInt(range);
- }
-
- public int genTerminalId()
- {
- int range = terminalIdMax - terminalIdMin + 1;
- return terminalIdMin + randomNum.nextInt(range);
- }
-
- public int genZip()
- {
- int range = zipMax - zipMin + 1;
- return zipMin + randomNum.nextInt(range);
- }
-
- public void setStopGeneration(boolean stopGeneration)
- {
- this.stopGeneration = stopGeneration;
- }
-
- /**
- * @return the tupleBlastSize
- */
- public int getTupleBlastSize()
- {
- return tupleBlastSize;
- }
-
- /**
- * @param tupleBlastSize the tupleBlastSize to set
- */
- public void setTupleBlastSize(int tupleBlastSize)
- {
- this.tupleBlastSize = tupleBlastSize;
- }
-
- private static final Logger logger = LoggerFactory.getLogger(MerchantTransactionGenerator.class);
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionInputHandler.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionInputHandler.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionInputHandler.java
deleted file mode 100644
index cdc829d..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/MerchantTransactionInputHandler.java
+++ /dev/null
@@ -1,116 +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 com.datatorrent.demos.frauddetect;
-
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.datatorrent.api.DefaultInputPort;
-import com.datatorrent.api.DefaultOutputPort;
-import com.datatorrent.common.util.BaseOperator;
-
-/**
- * Common utility class that can be used by all other operators to handle user input
- * captured from the Web socket input port.
- *
- * @since 0.9.0
- */
-public class MerchantTransactionInputHandler extends BaseOperator
-{
- public static final String KEY_BANK_ID_NUMBER = "bankIdNum"; // first 12 digits
- public static final String KEY_CREDIT_CARD_NUMBER = "ccNum"; // last 4 digits
- public static final String KEY_MERCHANT_ID = "merchantId";
- public static final String KEY_TERMINAL_ID = "terminalId";
- public static final String KEY_ZIP_CODE = "zipCode";
- public static final String KEY_AMOUNT = "amount";
- public transient DefaultOutputPort<MerchantTransaction> txOutputPort =
- new DefaultOutputPort<MerchantTransaction>();
- public transient DefaultInputPort<Map<String, String>> userTxInputPort = new DefaultInputPort<Map<String, String>>()
- {
- @Override
- public void process(Map<String, String> tuple)
- {
- try {
- txOutputPort.emit(processInput(tuple));
- } catch (Exception exc) {
- logger.error("Exception while handling the input", exc);
- }
- }
-
- };
-
- public MerchantTransaction processInput(Map<String, String> tuple)
- {
- String bankIdNum = null;
- String ccNum = null;
- String merchantId = null;
- Integer terminalId = null;
- Integer zipCode = null;
- Long amount = null;
- for (Map.Entry<String, String> e : tuple.entrySet()) {
- if (e.getKey().equals(KEY_BANK_ID_NUMBER)) {
- bankIdNum = e.getValue();
- }
- if (e.getKey().equals(KEY_CREDIT_CARD_NUMBER)) {
- ccNum = e.getValue();
- }
- if (e.getKey().equals(KEY_MERCHANT_ID)) {
- merchantId = e.getValue();
- }
- if (e.getKey().equals(KEY_TERMINAL_ID)) {
- terminalId = new Integer(e.getValue());
- }
- if (e.getKey().equals(KEY_ZIP_CODE)) {
- zipCode = new Integer(e.getValue());
- }
- if (e.getKey().equals(KEY_AMOUNT)) {
- amount = new Long(e.getValue());
- }
- }
-
- if (bankIdNum == null || ccNum == null || merchantId == null || terminalId == null || zipCode == null || amount == null) {
- throw new IllegalArgumentException("Missing required input!");
- }
-
- MerchantTransaction tx = new MerchantTransaction();
- tx.bankIdNum = bankIdNum;
- tx.ccNum = ccNum;
- tx.fullCcNum = bankIdNum + " " + ccNum;
- tx.merchantId = merchantId;
- tx.terminalId = terminalId;
- tx.zipCode = zipCode;
- tx.country = "USA";
- tx.amount = amount;
- tx.merchantType = tx.merchantId.equalsIgnoreCase(MerchantTransactionGenerator.merchantIds[2])
- || tx.merchantId.equalsIgnoreCase(MerchantTransactionGenerator.merchantIds[3])
- ? MerchantTransaction.MerchantType.INTERNET
- : MerchantTransaction.MerchantType.BRICK_AND_MORTAR;
- tx.transactionType = MerchantTransaction.TransactionType.POS;
-
- tx.userGenerated = true;
- tx.time = System.currentTimeMillis();
-
- return tx;
-
- }
-
- private static final Logger logger = LoggerFactory.getLogger(MerchantTransactionInputHandler.class);
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/SlidingWindowSumKeyVal.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/SlidingWindowSumKeyVal.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/SlidingWindowSumKeyVal.java
deleted file mode 100644
index 2701c14..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/SlidingWindowSumKeyVal.java
+++ /dev/null
@@ -1,99 +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 com.datatorrent.demos.frauddetect;
-
-import java.util.ArrayList;
-
-import com.datatorrent.api.DefaultOutputPort;
-import com.datatorrent.api.annotation.OutputPortFieldAnnotation;
-
-import com.datatorrent.lib.multiwindow.AbstractSlidingWindowKeyVal;
-import com.datatorrent.lib.util.KeyValPair;
-
-
-/**
- * Sliding window sum operator
- *
- * @since 0.9.0
- */
-public class SlidingWindowSumKeyVal<K, V extends Number> extends AbstractSlidingWindowKeyVal<K, V, SlidingWindowSumObject>
-{
-
- /**
- * Output port to emit simple moving average (SMA) of last N window as Double.
- */
- @OutputPortFieldAnnotation(optional = true)
- public final transient DefaultOutputPort<KeyValPair<K, Double>> doubleSum = new DefaultOutputPort<KeyValPair<K, Double>>();
- /**
- * Output port to emit simple moving average (SMA) of last N window as Float.
- */
- @OutputPortFieldAnnotation(optional = true)
- public final transient DefaultOutputPort<KeyValPair<K, Float>> floatSum = new DefaultOutputPort<KeyValPair<K, Float>>();
- /**
- * Output port to emit simple moving average (SMA) of last N window as Long.
- */
- @OutputPortFieldAnnotation(optional = true)
- public final transient DefaultOutputPort<KeyValPair<K, Long>> longSum = new DefaultOutputPort<KeyValPair<K, Long>>();
- /**
- * Output port to emit simple moving average (SMA) of last N window as
- * Integer.
- */
- @OutputPortFieldAnnotation(optional = true)
- public final transient DefaultOutputPort<KeyValPair<K, Integer>> integerSum = new DefaultOutputPort<KeyValPair<K, Integer>>();
-
-
- @Override
- public void processDataTuple(KeyValPair<K, V> tuple)
- {
- K key = tuple.getKey();
- ArrayList<SlidingWindowSumObject> stateList = buffer.get(key);
- if (stateList == null) {
- stateList = new ArrayList<SlidingWindowSumObject>();
- for (int i = 0; i < windowSize; ++i) {
- stateList.add(new SlidingWindowSumObject());
- }
- buffer.put(key, stateList);
- }
- SlidingWindowSumObject state = stateList.get(currentstate);
- state.add(tuple.getValue());
- }
-
- @Override
- public void emitTuple(K key, ArrayList<SlidingWindowSumObject> obj)
- {
- double sum = 0;
- for (int i = 0; i < obj.size(); ++i) {
- SlidingWindowSumObject state = obj.get(i);
- sum += state.getSum();
- }
- if (doubleSum.isConnected()) {
- doubleSum.emit(new KeyValPair<K, Double>(key, sum));
- }
- if (floatSum.isConnected()) {
- floatSum.emit(new KeyValPair<K, Float>(key, (float)sum));
- }
- if (longSum.isConnected()) {
- longSum.emit(new KeyValPair<K, Long>(key, (long)sum));
- }
- if (integerSum.isConnected()) {
- integerSum.emit(new KeyValPair<K, Integer>(key, (int)sum));
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/SlidingWindowSumObject.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/SlidingWindowSumObject.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/SlidingWindowSumObject.java
deleted file mode 100644
index 3fefb66..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/SlidingWindowSumObject.java
+++ /dev/null
@@ -1,53 +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 com.datatorrent.demos.frauddetect;
-
-
-import org.apache.commons.lang.mutable.MutableDouble;
-
-import com.datatorrent.lib.multiwindow.SimpleMovingAverageObject;
-
-/**
- * State object for sliding window sum
- *
- * @since 0.9.0
- */
-public class SlidingWindowSumObject extends SimpleMovingAverageObject
-{
-
- MutableDouble sum = new MutableDouble(0);
-
- public void add(Number n)
- {
- sum.add(n);
- }
-
- @Override
- public double getSum()
- {
- return sum.doubleValue();
- }
-
- @Override
- public void clear()
- {
- sum.setValue(0);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/TransactionStatsAggregator.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/TransactionStatsAggregator.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/TransactionStatsAggregator.java
deleted file mode 100644
index e226af0..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/TransactionStatsAggregator.java
+++ /dev/null
@@ -1,99 +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 com.datatorrent.demos.frauddetect;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.datatorrent.api.DefaultInputPort;
-import com.datatorrent.api.DefaultOutputPort;
-import com.datatorrent.common.util.BaseOperator;
-import com.datatorrent.demos.frauddetect.util.JsonUtils;
-import com.datatorrent.lib.util.HighLow;
-import com.datatorrent.lib.util.KeyValPair;
-
-/**
- * Operator to aggregate the min, max, sma, std-dev and variance for the given key.
- *
- * @since 0.9.0
- */
-public class TransactionStatsAggregator extends BaseOperator
-{
- public Map<MerchantKey, TransactionStatsData> aggrgateMap =
- new HashMap<MerchantKey, TransactionStatsData>();
- public final transient DefaultOutputPort<String> txDataOutputPort = new DefaultOutputPort<String>();
- public final transient DefaultInputPort<KeyValPair<MerchantKey, HighLow<Long>>> rangeInputPort =
- new DefaultInputPort<KeyValPair<MerchantKey, HighLow<Long>>>()
- {
- @Override
- public void process(KeyValPair<MerchantKey, HighLow<Long>> tuple)
- {
- TransactionStatsData data = getDataObjectFromMap(tuple.getKey());
- // HighLow is not currently typed, casting till it is fixed
- data.min = tuple.getValue().getLow();
- data.max = tuple.getValue().getHigh();
- }
-
- };
- public final transient DefaultInputPort<KeyValPair<MerchantKey, Long>> smaInputPort =
- new DefaultInputPort<KeyValPair<MerchantKey, Long>>()
- {
- @Override
- public void process(KeyValPair<MerchantKey, Long> tuple)
- {
- TransactionStatsData data = getDataObjectFromMap(tuple.getKey());
- data.sma = tuple.getValue();
- }
-
- };
-
- private TransactionStatsData getDataObjectFromMap(MerchantKey key)
- {
- TransactionStatsData data = aggrgateMap.get(key);
- if (data == null) {
- data = new TransactionStatsData();
- data.time = System.currentTimeMillis();
- data.merchantId = key.merchantId;
- data.terminalId = key.terminalId == null ? 0 : key.terminalId;
- data.zipCode = key.zipCode;
- data.merchantType = key.merchantType;
- aggrgateMap.put(key, data);
- }
- return data;
- }
-
- @Override
- public void endWindow()
- {
- for (Map.Entry<MerchantKey, TransactionStatsData> entry : aggrgateMap.entrySet()) {
- try {
- txDataOutputPort.emit(JsonUtils.toJson(entry.getValue()));
- } catch (IOException e) {
- logger.warn("Exception while converting object to JSON", e);
- }
- }
- aggrgateMap.clear();
- }
-
- private static final Logger logger = LoggerFactory.getLogger(TransactionStatsAggregator.class);
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/TransactionStatsData.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/TransactionStatsData.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/TransactionStatsData.java
deleted file mode 100644
index 4f899bc..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/TransactionStatsData.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 com.datatorrent.demos.frauddetect;
-
-/**
- * POJO to capture transaction data related to min, max, sma, std-dev, variance.
- *
- * @since 0.9.0
- */
-public class TransactionStatsData
-{
- public String merchantId;
- public int terminalId;
- public int zipCode;
- public MerchantTransaction.MerchantType merchantType;
- public long min;
- public long max;
- public double sma;
- public long time;
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/operator/HdfsStringOutputOperator.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/operator/HdfsStringOutputOperator.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/operator/HdfsStringOutputOperator.java
deleted file mode 100644
index 4b8f851..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/operator/HdfsStringOutputOperator.java
+++ /dev/null
@@ -1,72 +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 com.datatorrent.demos.frauddetect.operator;
-
-import java.io.File;
-
-import com.datatorrent.api.Context.DAGContext;
-import com.datatorrent.api.Context.OperatorContext;
-import com.datatorrent.lib.io.fs.AbstractFileOutputOperator;
-
-/**
- * Adapter for writing Strings to HDFS
- * <p>
- * Serializes tuples into a HDFS file.<br/>
- * </p>
- *
- * @since 0.9.4
- */
-public class HdfsStringOutputOperator extends AbstractFileOutputOperator<String>
-{
- private transient String outputFileName;
- private transient String contextId;
- private int index = 0;
-
- public HdfsStringOutputOperator()
- {
- setMaxLength(1024 * 1024);
- }
-
- @Override
- public void setup(OperatorContext context)
- {
- contextId = context.getValue(DAGContext.APPLICATION_NAME);
- outputFileName = File.separator + contextId +
- File.separator + "transactions.out.part";
- super.setup(context);
- }
-
- @Override
- public byte[] getBytesForTuple(String t)
- {
- return t.getBytes();
- }
-
- @Override
- protected String getFileName(String tuple)
- {
- return outputFileName;
- }
-
- @Override
- public String getPartFileName(String fileName, int part)
- {
- return fileName + part;
- }
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/operator/MongoDBOutputOperator.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/operator/MongoDBOutputOperator.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/operator/MongoDBOutputOperator.java
deleted file mode 100644
index 0171c00..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/operator/MongoDBOutputOperator.java
+++ /dev/null
@@ -1,188 +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 com.datatorrent.demos.frauddetect.operator;
-
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.validation.constraints.NotNull;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.mongodb.DB;
-import com.mongodb.DBCollection;
-import com.mongodb.DBObject;
-import com.mongodb.MongoClient;
-import com.mongodb.WriteConcern;
-import com.mongodb.WriteResult;
-import com.mongodb.util.JSON;
-
-import com.datatorrent.api.Context;
-import com.datatorrent.api.DefaultInputPort;
-import com.datatorrent.common.util.BaseOperator;
-
-
-/**
- * Operator to write data into MongoDB
- *
- * @since 0.9.0
- */
-public class MongoDBOutputOperator extends BaseOperator
-{
- @NotNull
- protected String hostName;
- @NotNull
- protected String dataBase;
- @NotNull
- protected String collection;
-
- protected WriteConcern writeConcern = WriteConcern.ACKNOWLEDGED;
-
- protected String userName;
- protected String passWord;
-
- protected transient MongoClient mongoClient;
- protected transient DB db;
- protected transient DBCollection dbCollection;
-
- protected List<DBObject> dataList = new ArrayList<DBObject>();
-
- public MongoDBOutputOperator()
- {
- }
-
- /**
- * Take the JSON formatted string and convert it to DBObject
- */
- public final transient DefaultInputPort<String> inputPort = new DefaultInputPort<String>()
- {
- @Override
- public void process(String tuple)
- {
- dataList.add((DBObject)JSON.parse(tuple));
- }
- };
-
- @Override
- public void setup(Context.OperatorContext context)
- {
- super.setup(context);
- try {
- mongoClient = new MongoClient(hostName);
- db = mongoClient.getDB(dataBase);
- if (userName != null && passWord != null) {
- if (!db.authenticate(userName, passWord.toCharArray())) {
- throw new IllegalArgumentException("MongoDB authentication failed. Illegal username and password for MongoDB!!");
- }
- }
- dbCollection = db.getCollection(collection);
- } catch (UnknownHostException ex) {
- logger.debug(ex.toString());
- }
- }
-
- @Override
- public void beginWindow(long windowId)
- {
- // nothing
- }
-
- @Override
- public void endWindow()
- {
- logger.debug("mongo datalist size: " + dataList.size());
- if (dataList.size() > 0) {
- WriteResult result = dbCollection.insert(dataList, writeConcern);
- logger.debug("Result for MongoDB insert: " + result);
- dataList.clear();
- }
- }
-
- @Override
- public void teardown()
- {
- if (mongoClient != null) {
- mongoClient.close();
- }
- }
-
- public String getHostName()
- {
- return hostName;
- }
-
- public void setHostName(String hostName)
- {
- this.hostName = hostName;
- }
-
- public String getDataBase()
- {
- return dataBase;
- }
-
- public void setDataBase(String dataBase)
- {
- this.dataBase = dataBase;
- }
-
- public String getCollection()
- {
- return collection;
- }
-
- public void setCollection(String collection)
- {
- this.collection = collection;
- }
-
- public String getUserName()
- {
- return userName;
- }
-
- public void setUserName(String userName)
- {
- this.userName = userName;
- }
-
- public String getPassWord()
- {
- return passWord;
- }
-
- public void setPassWord(String passWord)
- {
- this.passWord = passWord;
- }
-
- public WriteConcern getWriteConcern()
- {
- return writeConcern;
- }
-
- public void setWriteConcern(WriteConcern writeConcern)
- {
- this.writeConcern = writeConcern;
- }
-
- private static final Logger logger = LoggerFactory.getLogger(MongoDBOutputOperator.class);
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/util/JsonUtils.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/util/JsonUtils.java b/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/util/JsonUtils.java
deleted file mode 100644
index 60c200f..0000000
--- a/demos/frauddetect/src/main/java/com/datatorrent/demos/frauddetect/util/JsonUtils.java
+++ /dev/null
@@ -1,38 +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 com.datatorrent.demos.frauddetect.util;
-
-import java.io.IOException;
-
-import org.codehaus.jackson.map.ObjectMapper;
-
-/**
- * Utility class to deal with JSON and Object
- *
- * @since 0.9.0
- */
-public class JsonUtils
-{
- private static final ObjectMapper mapper = new ObjectMapper();
-
- public static String toJson(Object obj) throws IOException
- {
- return mapper.writeValueAsString(obj);
- }
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/main/resources/META-INF/properties.xml
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/main/resources/META-INF/properties.xml b/demos/frauddetect/src/main/resources/META-INF/properties.xml
deleted file mode 100644
index a3a3073..0000000
--- a/demos/frauddetect/src/main/resources/META-INF/properties.xml
+++ /dev/null
@@ -1,167 +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.
-
--->
-<configuration>
-<property>
- <name>dt.attr.STREAMING_WINDOW_SIZE_MILLIS</name>
- <value>1000</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.ccUserAlertQueryOutput.topic</name>
- <value>demos.app.frauddetect.fraudAlert</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.binUserAlertOutput.topic</name>
- <value>demos.app.frauddetect.fraudAlert</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.avgUserAlertQueryOutput.topic</name>
- <value>demos.app.frauddetect.fraudAlert</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.txSummaryWsOutput.topic</name>
- <value>demos.app.frauddetect.txSummary</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.bankInfoFraudDetector.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>10</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.bankInfoFraudDetector.threshold
- </name>
- <value>20</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.rangePerMerchant.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.txReceiver.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-<!-- property>
- <name>dt.application.frauddetect.operator.smaPerMerchant.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property-->
-<property>
- <name>dt.application.FraudDetectDemo.operator.smaPerMerchant.windowSize
- </name>
- <value>30</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.movingSum.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>10</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.movingSum.windowSize
- </name>
- <value>3</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.avgAlerter.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.avgAlerter.threshold
- </name>
- <value>1200</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.amountFraudDetector.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.amountFraudDetector.threshold
- </name>
- <value>420</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoTxStatsOutput.hostName</name>
- <value>localhost</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoTxStatsOutput.dataBase</name>
- <value>frauddetect</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoTxStatsOutput.collection</name>
- <value>txStats</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoBinAlertsOutput.hostName</name>
- <value>localhost</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoBinAlertsOutput.dataBase</name>
- <value>frauddetect</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoBinAlertsOutput.collection</name>
- <value>binAlerts</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoCcAlertsOutput.hostName</name>
- <value>localhost</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoCcAlertsOutput.dataBase</name>
- <value>frauddetect</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoCcAlertsOutput.collection</name>
- <value>ccAlerts</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoAvgAlertsOutput.hostName</name>
- <value>localhost</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoAvgAlertsOutput.dataBase</name>
- <value>frauddetect</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoAvgAlertsOutput.collection</name>
- <value>avgAlerts</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.txStatsAggregator.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-
-<property>
- <name>dt.application.FraudDetectDemo.port.*.attr.QUEUE_CAPACITY</name>
- <value>32000</value>
- </property>
- <property>
- <name>dt.application.FraudDetectDemo.operator.*.attr.MEMORY_MB</name>
- <value>2048</value>
- </property>
-
-</configuration>
-
-
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/site/conf/my-app-conf1.xml
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/site/conf/my-app-conf1.xml b/demos/frauddetect/src/site/conf/my-app-conf1.xml
deleted file mode 100644
index f35873b..0000000
--- a/demos/frauddetect/src/site/conf/my-app-conf1.xml
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!--
-
- 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.
-
--->
-<configuration>
- <property>
- <name>dt.attr.MASTER_MEMORY_MB</name>
- <value>1024</value>
- </property>
-</configuration>
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/test/java/com/datatorrent/demos/frauddetect/FrauddetectApplicationTest.java
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/test/java/com/datatorrent/demos/frauddetect/FrauddetectApplicationTest.java b/demos/frauddetect/src/test/java/com/datatorrent/demos/frauddetect/FrauddetectApplicationTest.java
deleted file mode 100644
index ef1f371..0000000
--- a/demos/frauddetect/src/test/java/com/datatorrent/demos/frauddetect/FrauddetectApplicationTest.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 com.datatorrent.demos.frauddetect;
-
-import org.junit.Test;
-import org.apache.hadoop.conf.Configuration;
-import com.datatorrent.api.LocalMode;
-
-/**
- * Fraud detection application test
- */
-public class FrauddetectApplicationTest
-{
-
- public FrauddetectApplicationTest()
- {
- }
-
- @Test
- public void testApplication() throws Exception
- {
- try {
- Application application = new Application();
- Configuration conf = new Configuration(false);
- conf.addResource("dt-site-frauddetect.xml");
- LocalMode lma = LocalMode.newInstance();
- lma.prepareDAG(application, conf);
- lma.getController().run(120000);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/test/resources/dt-site-frauddetect.xml
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/test/resources/dt-site-frauddetect.xml b/demos/frauddetect/src/test/resources/dt-site-frauddetect.xml
deleted file mode 100644
index 19771d8..0000000
--- a/demos/frauddetect/src/test/resources/dt-site-frauddetect.xml
+++ /dev/null
@@ -1,173 +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.
-
--->
-<configuration>
- <property>
- <name>dt.application.FraudDetectDemo.class</name>
- <value>com.datatorrent.demos.frauddetect.Application</value>
- <description>An alias for the application</description>
-</property>
-<property>
- <name>dt.attr.STREAMING_WINDOW_SIZE_MILLIS</name>
- <value>1000</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.ccUserAlertQueryOutput.topic</name>
- <value>demos.app.frauddetect.fraudAlert</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.binUserAlertOutput.topic</name>
- <value>demos.app.frauddetect.fraudAlert</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.avgUserAlertQueryOutput.topic</name>
- <value>demos.app.frauddetect.fraudAlert</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.txSummaryWsOutput.topic</name>
- <value>demos.app.frauddetect.txSummary</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.bankInfoFraudDetector.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>10</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.bankInfoFraudDetector.threshold
- </name>
- <value>20</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.rangePerMerchant.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.txReceiver.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-<!-- property>
- <name>dt.application.frauddetect.operator.smaPerMerchant.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property-->
-<property>
- <name>dt.application.FraudDetectDemo.operator.smaPerMerchant.windowSize
- </name>
- <value>30</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.movingSum.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>10</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.movingSum.windowSize
- </name>
- <value>3</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.avgAlerter.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.avgAlerter.threshold
- </name>
- <value>1200</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.amountFraudDetector.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.amountFraudDetector.threshold
- </name>
- <value>420</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoTxStatsOutput.hostName</name>
- <value>localhost</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoTxStatsOutput.dataBase</name>
- <value>frauddetect</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoTxStatsOutput.collection</name>
- <value>txStats</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoBinAlertsOutput.hostName</name>
- <value>localhost</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoBinAlertsOutput.dataBase</name>
- <value>frauddetect</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoBinAlertsOutput.collection</name>
- <value>binAlerts</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoCcAlertsOutput.hostName</name>
- <value>localhost</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoCcAlertsOutput.dataBase</name>
- <value>frauddetect</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoCcAlertsOutput.collection</name>
- <value>ccAlerts</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoAvgAlertsOutput.hostName</name>
- <value>localhost</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoAvgAlertsOutput.dataBase</name>
- <value>frauddetect</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.mongoAvgAlertsOutput.collection</name>
- <value>avgAlerts</value>
-</property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.txStatsAggregator.attr.APPLICATION_WINDOW_COUNT
- </name>
- <value>1</value>
-</property>
-
-<property>
- <name>dt.application.FraudDetectDemo.port.*.attr.QUEUE_CAPACITY</name>
- <value>32000</value>
- </property>
-<property>
- <name>dt.application.FraudDetectDemo.operator.*.attr.MEMORY_MB</name>
- <value>2048</value>
-</property>
-
-
-</configuration>
-
-
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/frauddetect/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/demos/frauddetect/src/test/resources/log4j.properties b/demos/frauddetect/src/test/resources/log4j.properties
deleted file mode 100644
index cf0d19e..0000000
--- a/demos/frauddetect/src/test/resources/log4j.properties
+++ /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.
-#
-
-log4j.rootLogger=DEBUG,CONSOLE
-
-log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
-log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
-log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c{2} %M - %m%n
-log4j.appender.CONSOLE.threshold=${test.log.console.threshold}
-test.log.console.threshold=DEBUG
-
-log4j.appender.RFA=org.apache.log4j.RollingFileAppender
-log4j.appender.RFA.layout=org.apache.log4j.PatternLayout
-log4j.appender.RFA.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c{2} %M - %m%n
-log4j.appender.RFA.File=/tmp/app.log
-
-# to enable, add SYSLOG to rootLogger
-log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender
-log4j.appender.SYSLOG.syslogHost=127.0.0.1
-log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout
-log4j.appender.SYSLOG.layout.conversionPattern=${dt.cid} %-5p [%t] %c{2} %x - %m%n
-log4j.appender.SYSLOG.Facility=LOCAL1
-
-log4j.logger.org=info
-#log4j.logger.org.apache.commons.beanutils=warn
-log4j.logger.com.datatorrent=debug
-log4j.logger.org.apache.apex=debug
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/highlevelapi/pom.xml
----------------------------------------------------------------------
diff --git a/demos/highlevelapi/pom.xml b/demos/highlevelapi/pom.xml
deleted file mode 100644
index 1f25703..0000000
--- a/demos/highlevelapi/pom.xml
+++ /dev/null
@@ -1,141 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
-
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>high-level-api-demo</artifactId>
- <packaging>jar</packaging>
-
- <name>Apache Apex Malhar High-Level API Demo</name>
- <description>Apex demo applications that use High-level API to construct a dag</description>
-
- <parent>
- <groupId>org.apache.apex</groupId>
- <artifactId>malhar-demos</artifactId>
- <version>3.7.0-SNAPSHOT</version>
- </parent>
-
- <build>
- <plugins>
-
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <version>1.9.1</version>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <phase>package</phase>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <configuration>
- <artifacts>
- <artifact>
- <file>target/${project.artifactId}-${project.version}.apa</file>
- <type>apa</type>
- </artifact>
- </artifacts>
- <skipAttach>false</skipAttach>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.10</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <!-- required by twitter demo -->
- <groupId>org.twitter4j</groupId>
- <artifactId>twitter4j-core</artifactId>
- <version>4.0.4</version>
- </dependency>
- <dependency>
- <!-- required by twitter demo -->
- <groupId>org.twitter4j</groupId>
- <artifactId>twitter4j-stream</artifactId>
- <version>4.0.4</version>
- </dependency>
- <dependency>
- <groupId>org.apache.apex</groupId>
- <artifactId>malhar-contrib</artifactId>
- <version>${project.version}</version>
- <exclusions>
- <exclusion>
- <groupId>*</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.apache.apex</groupId>
- <artifactId>malhar-stream</artifactId>
- <version>${project.version}</version>
- <exclusions>
- <exclusion>
- <groupId>*</groupId>
- <artifactId>*</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- <version>2.3.1</version>
- </dependency>
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <version>1.4.192</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>2.9.1</version>
- </dependency>
- <dependency>
- <!--This dependency is needed for StreamingWordExtractTest-->
- <groupId>org.codehaus.janino</groupId>
- <artifactId>commons-compiler</artifactId>
- <version>2.7.8</version>
- <type>jar</type>
- </dependency>
- <dependency>
- <!--This dependency is needed for StreamingWordExtractTest-->
- <groupId>org.codehaus.janino</groupId>
- <artifactId>janino</artifactId>
- <version>2.7.8</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-
-</project>
http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/d5bf96ca/demos/highlevelapi/src/assemble/appPackage.xml
----------------------------------------------------------------------
diff --git a/demos/highlevelapi/src/assemble/appPackage.xml b/demos/highlevelapi/src/assemble/appPackage.xml
deleted file mode 100644
index 4138cf2..0000000
--- a/demos/highlevelapi/src/assemble/appPackage.xml
+++ /dev/null
@@ -1,59 +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.
-
--->
-<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
- <id>appPackage</id>
- <formats>
- <format>jar</format>
- </formats>
- <includeBaseDirectory>false</includeBaseDirectory>
- <fileSets>
- <fileSet>
- <directory>${basedir}/target/</directory>
- <outputDirectory>/app</outputDirectory>
- <includes>
- <include>${project.artifactId}-${project.version}.jar</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${basedir}/target/deps</directory>
- <outputDirectory>/lib</outputDirectory>
- </fileSet>
- <fileSet>
- <directory>${basedir}/src/site/conf</directory>
- <outputDirectory>/conf</outputDirectory>
- <includes>
- <include>*.xml</include>
- </includes>
- </fileSet>
- <fileSet>
- <directory>${basedir}/src/main/resources/META-INF</directory>
- <outputDirectory>/META-INF</outputDirectory>
- </fileSet>
- <fileSet>
- <directory>${basedir}/src/main/resources/app</directory>
- <outputDirectory>/app</outputDirectory>
- </fileSet>
- </fileSets>
-
-</assembly>
-