|
|
@ -55,6 +55,7 @@ import org.wso2.carbon.registry.api.Resource;
|
|
|
|
import javax.net.ssl.KeyManagerFactory;
|
|
|
|
import javax.net.ssl.KeyManagerFactory;
|
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
|
import javax.net.ssl.SSLContext;
|
|
|
|
import javax.net.ssl.TrustManagerFactory;
|
|
|
|
import javax.net.ssl.TrustManagerFactory;
|
|
|
|
|
|
|
|
import javax.persistence.EntityExistsException;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.InputStream;
|
|
|
@ -303,7 +304,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
|
|
|
|
public boolean createGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
|
|
|
|
throws GeoLocationBasedServiceException, AlertAlreadyExistException {
|
|
|
|
throws GeoLocationBasedServiceException {
|
|
|
|
return saveGeoAlert(alert, identifier, alertType, false);
|
|
|
|
return saveGeoAlert(alert, identifier, alertType, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -315,7 +316,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
|
|
|
|
public boolean updateGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType)
|
|
|
|
throws GeoLocationBasedServiceException, AlertAlreadyExistException {
|
|
|
|
throws GeoLocationBasedServiceException {
|
|
|
|
return saveGeoAlert(alert, identifier, alertType, true);
|
|
|
|
return saveGeoAlert(alert, identifier, alertType, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -423,7 +424,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean saveGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType, boolean isUpdate)
|
|
|
|
public boolean saveGeoAlert(Alert alert, DeviceIdentifier identifier, String alertType, boolean isUpdate)
|
|
|
|
throws GeoLocationBasedServiceException, AlertAlreadyExistException {
|
|
|
|
throws GeoLocationBasedServiceException {
|
|
|
|
|
|
|
|
|
|
|
|
Type type = new TypeToken<Map<String, String>>() {
|
|
|
|
Type type = new TypeToken<Map<String, String>>() {
|
|
|
|
}.getType();
|
|
|
|
}.getType();
|
|
|
@ -465,38 +466,23 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
"Unrecognized execution plan type: " + alertType + " while creating geo alert");
|
|
|
|
"Unrecognized execution plan type: " + alertType + " while creating geo alert");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//persist alert in registry
|
|
|
|
|
|
|
|
updateRegistry(getRegistryPath(alertType, identifier, alert.getQueryName()), identifier, content,
|
|
|
|
|
|
|
|
options);
|
|
|
|
|
|
|
|
|
|
|
|
//deploy alert into event processor
|
|
|
|
//deploy alert into event processor
|
|
|
|
EventProcessorAdminServiceStub eventprocessorStub = null;
|
|
|
|
EventProcessorAdminServiceStub eventprocessorStub = null;
|
|
|
|
String action = (isUpdate ? "updating" : "creating");
|
|
|
|
String action = (isUpdate ? "updating" : "creating");
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ExecutionPlanConfigurationDto[] allActiveExecutionPlanConfigs = null;
|
|
|
|
|
|
|
|
String activeExecutionPlan = null;
|
|
|
|
|
|
|
|
String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName(),
|
|
|
|
|
|
|
|
identifier.getId());
|
|
|
|
|
|
|
|
eventprocessorStub = getEventProcessorAdminServiceStub();
|
|
|
|
eventprocessorStub = getEventProcessorAdminServiceStub();
|
|
|
|
String parsedTemplate = parseTemplate(alertType, parseMap);
|
|
|
|
String parsedTemplate = parseTemplate(alertType, parseMap);
|
|
|
|
String validationResponse = eventprocessorStub.validateExecutionPlan(parsedTemplate);
|
|
|
|
String validationResponse = eventprocessorStub.validateExecutionPlan(parsedTemplate);
|
|
|
|
if (validationResponse.equals("success")) {
|
|
|
|
if (validationResponse.equals("success")) {
|
|
|
|
allActiveExecutionPlanConfigs = eventprocessorStub.getAllActiveExecutionPlanConfigurations();
|
|
|
|
|
|
|
|
if (isUpdate) {
|
|
|
|
if (isUpdate) {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
|
|
|
|
String executionPlanName = getExecutionPlanName(alertType, alert.getQueryName(),
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
identifier.getId());
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
|
|
|
|
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
|
|
|
|
eventprocessorStub.editActiveExecutionPlan(parsedTemplate, executionPlanName);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
for (ExecutionPlanConfigurationDto activeExectionPlanConfig:allActiveExecutionPlanConfigs) {
|
|
|
|
|
|
|
|
activeExecutionPlan = activeExectionPlanConfig.getExecutionPlan();
|
|
|
|
|
|
|
|
if (activeExecutionPlan.contains(executionPlanName)) {
|
|
|
|
|
|
|
|
throw new AlertAlreadyExistException("Execution plan already exists with name "
|
|
|
|
|
|
|
|
+ executionPlanName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
updateRegistry(getRegistryPath(alertType, identifier, alert.getQueryName()), identifier, content,
|
|
|
|
|
|
|
|
options);
|
|
|
|
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
eventprocessorStub.deployExecutionPlan(parsedTemplate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -592,8 +578,6 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
|
|
|
|
private String getExecutionPlanName(String alertType, String queryName, String deviceId) {
|
|
|
|
private String getExecutionPlanName(String alertType, String queryName, String deviceId) {
|
|
|
|
if ("Traffic".equals(alertType)) {
|
|
|
|
if ("Traffic".equals(alertType)) {
|
|
|
|
return "Geo-ExecutionPlan-Traffic_" + queryName + "_alert";
|
|
|
|
return "Geo-ExecutionPlan-Traffic_" + queryName + "_alert";
|
|
|
|
} else if ("Speed".equals(alertType)) {
|
|
|
|
|
|
|
|
return "Geo-ExecutionPlan-" + alertType + "---" + deviceId + "_alert";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return "Geo-ExecutionPlan-" + alertType + "_" + queryName + "---_" + deviceId + "_alert";
|
|
|
|
return "Geo-ExecutionPlan-" + alertType + "_" + queryName + "---_" + deviceId + "_alert";
|
|
|
|
}
|
|
|
|
}
|
|
|
|