|
|
@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl.admin;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.axis2.AxisFault;
|
|
|
|
import org.apache.axis2.AxisFault;
|
|
|
|
import org.apache.axis2.client.Options;
|
|
|
|
import org.apache.axis2.client.Options;
|
|
|
|
|
|
|
|
import org.apache.axis2.client.Stub;
|
|
|
|
import org.apache.axis2.java.security.SSLProtocolSocketFactory;
|
|
|
|
import org.apache.axis2.java.security.SSLProtocolSocketFactory;
|
|
|
|
import org.apache.axis2.transport.http.HTTPConstants;
|
|
|
|
import org.apache.axis2.transport.http.HTTPConstants;
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
@ -119,12 +120,14 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
private static final String IOT_MGT_PORT = "${iot.manager.https.port}";
|
|
|
|
private static final String IOT_MGT_PORT = "${iot.manager.https.port}";
|
|
|
|
private static final String IOT_MGT_HOST_NAME = "${iot.manager.host}";
|
|
|
|
private static final String IOT_MGT_HOST_NAME = "${iot.manager.host}";
|
|
|
|
private static final String DAS_URL = DEFAULT_HTTP_PROTOCOL + "://" + DAS_HOST_NAME
|
|
|
|
private static final String DAS_URL = DEFAULT_HTTP_PROTOCOL + "://" + DAS_HOST_NAME
|
|
|
|
+ ":" + DAS_PORT + "/services/CarbonAppUploader" + "/";
|
|
|
|
+ ":" + DAS_PORT + "/services/CarbonAppUploader/";
|
|
|
|
private static final String DAS_EVENT_RECEIVER_EP = DEFAULT_HTTP_PROTOCOL + "://" + DAS_HOST_NAME
|
|
|
|
private static final String DAS_EVENT_RECEIVER_EP = DEFAULT_HTTP_PROTOCOL + "://" + DAS_HOST_NAME
|
|
|
|
+ ":" + DAS_PORT + "/services/EventReceiverAdminService" + "/";
|
|
|
|
+ ":" + DAS_PORT + "/services/EventReceiverAdminService/";
|
|
|
|
|
|
|
|
private static final String DAS_EVENT_STREAM_EP = DEFAULT_HTTP_PROTOCOL + "://" + DAS_HOST_NAME
|
|
|
|
|
|
|
|
+ ":" + DAS_PORT + "/services/EventStreamAdminService/";
|
|
|
|
|
|
|
|
|
|
|
|
private static final String IOT_MGT_URL = DEFAULT_HTTP_PROTOCOL + "://" + IOT_MGT_HOST_NAME
|
|
|
|
private static final String IOT_MGT_URL = DEFAULT_HTTP_PROTOCOL + "://" + IOT_MGT_HOST_NAME
|
|
|
|
+ ":" + IOT_MGT_PORT + "/services/CarbonAppUploader" + "/";
|
|
|
|
+ ":" + IOT_MGT_PORT + "/services/CarbonAppUploader/";
|
|
|
|
private static final String MEDIA_TYPE_XML = "application/xml";
|
|
|
|
private static final String MEDIA_TYPE_XML = "application/xml";
|
|
|
|
private static final String DEVICE_MANAGEMENT_TYPE = "device_management";
|
|
|
|
private static final String DEVICE_MANAGEMENT_TYPE = "device_management";
|
|
|
|
private static final String TENANT_DOMAIN_PROPERTY = "\\$\\{tenant-domain\\}";
|
|
|
|
private static final String TENANT_DOMAIN_PROPERTY = "\\$\\{tenant-domain\\}";
|
|
|
@ -134,7 +137,6 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
@POST
|
|
|
|
@POST
|
|
|
|
@Path("/deploy/{type}")
|
|
|
|
@Path("/deploy/{type}")
|
|
|
|
public Response doPublish(@PathParam("type") String type) {
|
|
|
|
public Response doPublish(@PathParam("type") String type) {
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
//Getting the tenant Domain
|
|
|
|
//Getting the tenant Domain
|
|
|
|
tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
|
tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
|
|
@ -159,17 +161,73 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
|
|
|
|
String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
|
|
|
|
jwtClient.getJwtToken(tenantAdminUser).getBytes()));
|
|
|
|
jwtClient.getJwtToken(tenantAdminUser).getBytes()));
|
|
|
|
|
|
|
|
|
|
|
|
List<Header> list = new ArrayList<Header>();
|
|
|
|
List<Header> list = new ArrayList<>();
|
|
|
|
Header httpHeader = new Header();
|
|
|
|
Header httpHeader = new Header();
|
|
|
|
httpHeader.setName(AUTHORIZATION_HEADER);
|
|
|
|
httpHeader.setName(AUTHORIZATION_HEADER);
|
|
|
|
httpHeader.setValue(authValue);
|
|
|
|
httpHeader.setValue(authValue);
|
|
|
|
list.add(httpHeader);//"https"
|
|
|
|
list.add(httpHeader);//"https"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> streamFileList = getStreamsList(type);
|
|
|
|
|
|
|
|
List<String> receiverFileList = getReceiversList(type);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
|
|
|
|
|
|
|
if (streamFileList != null) {
|
|
|
|
|
|
|
|
publishDynamicEventStream(type, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, streamFileList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (receiverFileList != null) {
|
|
|
|
|
|
|
|
publishDynamicEventReceivers(type, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, receiverFileList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (deployAnalyticsCapp(type, list)){
|
|
|
|
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST)
|
|
|
|
|
|
|
|
.entity("\"Error, Artifact does not exist.\"").build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (receiverFileList != null) {
|
|
|
|
|
|
|
|
publishDynamicEventReceivers(type, tenantDomain, receiverFileList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
Registry registry = DeviceMgtAPIUtils.getRegistryService().getConfigSystemRegistry(tenantId);
|
|
|
|
|
|
|
|
if (!registry.resourceExists(DEFAULT_RESOURCE_LOCATION + type + ".exist")) {
|
|
|
|
|
|
|
|
Resource resource = new ResourceImpl();
|
|
|
|
|
|
|
|
resource.setContent("</exist>");
|
|
|
|
|
|
|
|
resource.setMediaType(MEDIA_TYPE_XML);
|
|
|
|
|
|
|
|
registry.put(DEFAULT_RESOURCE_LOCATION + type + ".exist", resource);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Response.status(Response.Status.CREATED).entity("\"OK. \\n Successfully uploaded the artifacts.\"")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
} catch (AxisFault e) {
|
|
|
|
|
|
|
|
log.error("failed to publish event definitions for tenantDomain:" + tenantDomain, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
|
|
|
log.error("Failed to connect with the remote services:" + tenantDomain, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
|
|
|
|
log.error("Failed to generate jwt token for tenantDomain:" + tenantDomain, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
log.error("Failed to connect with the user store, tenantDomain: " + tenantDomain, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
|
|
|
} catch (CertificateException | UnrecoverableKeyException | KeyStoreException |
|
|
|
|
|
|
|
|
KeyManagementException | IOException | NoSuchAlgorithmException e) {
|
|
|
|
|
|
|
|
log.error("Failed to access keystore for, tenantDomain: " + tenantDomain, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
|
|
|
} catch (RegistryException e) {
|
|
|
|
|
|
|
|
log.error("Failed to load tenant, tenantDomain: " + tenantDomain, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
log.error("Invalid stream definition for device type" + type + " for tenant, tenantDomain: " + tenantDomain, e);
|
|
|
|
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean deployAnalyticsCapp(@PathParam("type") String type, List<Header> list) throws IOException, RegistryException {
|
|
|
|
|
|
|
|
CarbonAppUploaderStub carbonAppUploaderStub = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
File directory = new File(CAR_FILE_LOCATION + File.separator + type);
|
|
|
|
File directory = new File(CAR_FILE_LOCATION + File.separator + type);
|
|
|
|
if (directory.isDirectory() && directory.exists()) {
|
|
|
|
if (directory.isDirectory() && directory.exists()) {
|
|
|
|
UploadedFileItem[] uploadedFileItems = loadCappFromFileSystem(type);
|
|
|
|
UploadedFileItem[] uploadedFileItems = loadCappFromFileSystem(type);
|
|
|
|
if (uploadedFileItems.length > 0) {
|
|
|
|
if (uploadedFileItems.length > 0) {
|
|
|
|
CarbonAppUploaderStub carbonAppUploaderStub = new CarbonAppUploaderStub(Utils.replaceSystemProperty(
|
|
|
|
carbonAppUploaderStub = new CarbonAppUploaderStub(Utils.replaceSystemProperty(
|
|
|
|
IOT_MGT_URL));
|
|
|
|
IOT_MGT_URL));
|
|
|
|
Options appUploaderOptions = carbonAppUploaderStub._getServiceClient().getOptions();
|
|
|
|
Options appUploaderOptions = carbonAppUploaderStub._getServiceClient().getOptions();
|
|
|
|
if (appUploaderOptions == null) {
|
|
|
|
if (appUploaderOptions == null) {
|
|
|
@ -198,36 +256,14 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
carbonAppUploaderStub._getServiceClient().setOptions(appUploaderOptions);
|
|
|
|
carbonAppUploaderStub._getServiceClient().setOptions(appUploaderOptions);
|
|
|
|
carbonAppUploaderStub.uploadApp(uploadedFileItems);
|
|
|
|
carbonAppUploaderStub.uploadApp(uploadedFileItems);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
Registry registry = DeviceMgtAPIUtils.getRegistryService().getConfigSystemRegistry(tenantId);
|
|
|
|
|
|
|
|
if (!registry.resourceExists(DEFAULT_RESOURCE_LOCATION + type + ".exist")) {
|
|
|
|
|
|
|
|
Resource resource = new ResourceImpl();
|
|
|
|
|
|
|
|
resource.setContent("</exist>");
|
|
|
|
|
|
|
|
resource.setMediaType(MEDIA_TYPE_XML);
|
|
|
|
|
|
|
|
registry.put(DEFAULT_RESOURCE_LOCATION + type + ".exist", resource);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
|
|
|
|
|
|
|
publishDynamicEventReceivers(type, tenantDomain);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
publishDynamicEventReceivers(type,MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
|
|
|
|
|
|
publishDynamicEventStream(type,MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return Response.status(Response.Status.BAD_REQUEST)
|
|
|
|
return true;
|
|
|
|
.entity("\"Error, Artifact does not exist.\"").build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
} catch (Exception e) {
|
|
|
|
} finally {
|
|
|
|
log.error("Capp deployment failed due to " + e.getMessage(), e);
|
|
|
|
cleanup(carbonAppUploaderStub);
|
|
|
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(
|
|
|
|
|
|
|
|
"\"Error, Artifact deployment has failed\"").build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Response.status(Response.Status.CREATED).entity("\"OK. \\n Successfully uploaded the artifacts.\"")
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
@ -235,7 +271,7 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Response getStatus(@PathParam("type") String deviceType) {
|
|
|
|
public Response getStatus(@PathParam("type") String deviceType) {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
Registry registry = null;
|
|
|
|
Registry registry;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
registry = DeviceMgtAPIUtils.getRegistryService().getConfigSystemRegistry(tenantId);
|
|
|
|
registry = DeviceMgtAPIUtils.getRegistryService().getConfigSystemRegistry(tenantId);
|
|
|
|
if (registry.resourceExists(DEFAULT_RESOURCE_LOCATION + deviceType + ".exist")) {
|
|
|
|
if (registry.resourceExists(DEFAULT_RESOURCE_LOCATION + deviceType + ".exist")) {
|
|
|
@ -251,19 +287,20 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void publishDynamicEventReceivers(String deviceType, String tenantDomain){
|
|
|
|
private void publishDynamicEventReceivers(String deviceType, String tenantDomain, List<String> receiversList)
|
|
|
|
|
|
|
|
throws IOException, UserStoreException, JWTClientException {
|
|
|
|
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
|
|
|
|
EventReceiverAdminServiceStub receiverAdminServiceStub = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
receiverAdminServiceStub = new EventReceiverAdminServiceStub
|
|
|
|
EventReceiverAdminServiceStub receiverAdminServiceStub = new EventReceiverAdminServiceStub(Utils.replaceSystemProperty(DAS_EVENT_RECEIVER_EP));
|
|
|
|
(Utils.replaceSystemProperty(DAS_EVENT_RECEIVER_EP));
|
|
|
|
Options eventReciverOptions = receiverAdminServiceStub._getServiceClient().getOptions();
|
|
|
|
Options eventReciverOptions = receiverAdminServiceStub._getServiceClient().getOptions();
|
|
|
|
if (eventReciverOptions == null) {
|
|
|
|
if (eventReciverOptions == null) {
|
|
|
|
eventReciverOptions = new Options();
|
|
|
|
eventReciverOptions = new Options();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String username=null;
|
|
|
|
String username;
|
|
|
|
if(!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
|
|
|
if(!tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) {
|
|
|
|
username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm()
|
|
|
|
.getRealmConfiguration().getAdminUserName()+"@"+tenantDomain;
|
|
|
|
.getRealmConfiguration().getAdminUserName()+"@"+tenantDomain;
|
|
|
@ -278,7 +315,7 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
|
|
|
|
String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
|
|
|
|
jwtClient.getJwtToken(username).getBytes()));
|
|
|
|
jwtClient.getJwtToken(username).getBytes()));
|
|
|
|
|
|
|
|
|
|
|
|
List<Header> list = new ArrayList<Header>();
|
|
|
|
List<Header> list = new ArrayList<>();
|
|
|
|
Header httpHeader = new Header();
|
|
|
|
Header httpHeader = new Header();
|
|
|
|
httpHeader.setName(AUTHORIZATION_HEADER);
|
|
|
|
httpHeader.setName(AUTHORIZATION_HEADER);
|
|
|
|
httpHeader.setValue(authValue);
|
|
|
|
httpHeader.setValue(authValue);
|
|
|
@ -291,36 +328,24 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
|
|
|
|
|
|
|
receiverAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
|
|
|
|
receiverAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
|
|
|
|
|
|
|
|
|
|
|
|
List<String> receiversList = getReceiversList(deviceType);
|
|
|
|
|
|
|
|
for (String receiverContent:receiversList) {
|
|
|
|
for (String receiverContent:receiversList) {
|
|
|
|
receiverAdminServiceStub.deployEventReceiverConfiguration(receiverContent);
|
|
|
|
receiverAdminServiceStub.deployEventReceiverConfiguration(receiverContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (AxisFault e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
cleanup(receiverAdminServiceStub);
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void publishDynamicEventStream(String deviceType, String tenantDomain, List<String> streamList)
|
|
|
|
|
|
|
|
throws IOException, UserStoreException, JWTClientException, ParseException {
|
|
|
|
|
|
|
|
|
|
|
|
private void publishDynamicEventStream(String deviceType, String tenantDomain){
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().startTenantFlow();
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
|
|
|
|
|
|
|
EventStreamAdminServiceStub eventStreamAdminServiceStub = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
eventStreamAdminServiceStub = new EventStreamAdminServiceStub
|
|
|
|
EventStreamAdminServiceStub eventStreamAdminServiceStub = new EventStreamAdminServiceStub(Utils.replaceSystemProperty(DAS_EVENT_RECEIVER_EP));
|
|
|
|
(Utils.replaceSystemProperty(DAS_EVENT_STREAM_EP));
|
|
|
|
Options eventReciverOptions = eventStreamAdminServiceStub._getServiceClient().getOptions();
|
|
|
|
Options eventReciverOptions = eventStreamAdminServiceStub._getServiceClient().getOptions();
|
|
|
|
if (eventReciverOptions == null) {
|
|
|
|
if (eventReciverOptions == null) {
|
|
|
|
eventReciverOptions = new Options();
|
|
|
|
eventReciverOptions = new Options();
|
|
|
@ -340,7 +365,7 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
|
|
|
|
String authValue = AUTHORIZATION_HEADER_VALUE + " " + new String(Base64.encodeBase64(
|
|
|
|
jwtClient.getJwtToken(username).getBytes()));
|
|
|
|
jwtClient.getJwtToken(username).getBytes()));
|
|
|
|
|
|
|
|
|
|
|
|
List<Header> list = new ArrayList<Header>();
|
|
|
|
List<Header> list = new ArrayList<>();
|
|
|
|
Header httpHeader = new Header();
|
|
|
|
Header httpHeader = new Header();
|
|
|
|
httpHeader.setName(AUTHORIZATION_HEADER);
|
|
|
|
httpHeader.setName(AUTHORIZATION_HEADER);
|
|
|
|
httpHeader.setValue(authValue);
|
|
|
|
httpHeader.setValue(authValue);
|
|
|
@ -353,41 +378,28 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
, Integer.parseInt(Utils.replaceSystemProperty(DAS_PORT))));
|
|
|
|
|
|
|
|
|
|
|
|
eventStreamAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
|
|
|
|
eventStreamAdminServiceStub._getServiceClient().setOptions(eventReciverOptions);
|
|
|
|
|
|
|
|
|
|
|
|
List<String> streamList = getStreamsList(deviceType);
|
|
|
|
|
|
|
|
for (String streamContent:streamList) {
|
|
|
|
for (String streamContent:streamList) {
|
|
|
|
JSONParser jsonParser = new JSONParser();
|
|
|
|
JSONParser jsonParser = new JSONParser();
|
|
|
|
JSONObject steamJson = (JSONObject)jsonParser.parse(streamContent);
|
|
|
|
JSONObject steamJson = (JSONObject)jsonParser.parse(streamContent);
|
|
|
|
String name = (String) steamJson.get("name");
|
|
|
|
String name = (String) steamJson.get("name");
|
|
|
|
String version = (String) steamJson.get("version");
|
|
|
|
String version = (String) steamJson.get("version");
|
|
|
|
String streamId = name +":"+version;
|
|
|
|
String streamId = name +":"+version;
|
|
|
|
if(eventStreamAdminServiceStub.getStreamDefinitionAsString(streamId)==null) {
|
|
|
|
if (eventStreamAdminServiceStub.getStreamDefinitionDto(streamId) == null) {
|
|
|
|
|
|
|
|
|
|
|
|
eventStreamAdminServiceStub.addEventStreamDefinitionAsString(streamContent);
|
|
|
|
eventStreamAdminServiceStub.addEventStreamDefinitionAsString(streamContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (AxisFault e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (JWTClientException e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} catch (ParseException e) {
|
|
|
|
|
|
|
|
log.error("publishing dynamic event receiver is failed due to " + e.getMessage(), e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
cleanup(eventStreamAdminServiceStub);
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getReceiversList(String deviceType) throws IOException {
|
|
|
|
private List<String> getReceiversList(String deviceType) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
File directory = new File(CAR_FILE_LOCATION + File.separator + deviceType+File.separator+"receiver");
|
|
|
|
File directory = new File(CAR_FILE_LOCATION + File.separator + deviceType+File.separator+"receiver");
|
|
|
|
|
|
|
|
if (!directory.exists()) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
File[] receiverFiles = directory.listFiles(new FilenameFilter() {
|
|
|
|
File[] receiverFiles = directory.listFiles(new FilenameFilter() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean accept(File dir, String name) {
|
|
|
|
public boolean accept(File dir, String name) {
|
|
|
@ -396,8 +408,8 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
});
|
|
|
|
});
|
|
|
|
List<String> receiverList = new ArrayList<>();
|
|
|
|
List<String> receiverList = new ArrayList<>();
|
|
|
|
for (File receiverFile:receiverFiles) {
|
|
|
|
for (File receiverFile:receiverFiles) {
|
|
|
|
String receiverContent =new String(Files.readAllBytes(receiverFile.toPath()));
|
|
|
|
String receiverContentTemplate =new String(Files.readAllBytes(receiverFile.toPath()));
|
|
|
|
receiverContent.replaceAll(TENANT_DOMAIN_PROPERTY,tenantDomain.toLowerCase());
|
|
|
|
final String receiverContent = receiverContentTemplate.replaceAll(TENANT_DOMAIN_PROPERTY, tenantDomain.toLowerCase());
|
|
|
|
receiverList.add(receiverContent);
|
|
|
|
receiverList.add(receiverContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -405,8 +417,10 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getStreamsList(String deviceType) throws IOException {
|
|
|
|
private List<String> getStreamsList(String deviceType) throws IOException {
|
|
|
|
|
|
|
|
|
|
|
|
File directory = new File(CAR_FILE_LOCATION + File.separator + deviceType+File.separator+"streams");
|
|
|
|
File directory = new File(CAR_FILE_LOCATION + File.separator + deviceType+File.separator+"streams");
|
|
|
|
|
|
|
|
if (!directory.exists()) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
File[] receiverFiles = directory.listFiles(new FilenameFilter() {
|
|
|
|
File[] receiverFiles = directory.listFiles(new FilenameFilter() {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean accept(File dir, String name) {
|
|
|
|
public boolean accept(File dir, String name) {
|
|
|
@ -415,11 +429,9 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
});
|
|
|
|
});
|
|
|
|
List<String> streamList = new ArrayList<>();
|
|
|
|
List<String> streamList = new ArrayList<>();
|
|
|
|
for (File StreamFile:receiverFiles) {
|
|
|
|
for (File StreamFile:receiverFiles) {
|
|
|
|
String receiverContent =new String(Files.readAllBytes(StreamFile.toPath()));
|
|
|
|
String streamContent =new String(Files.readAllBytes(StreamFile.toPath()));
|
|
|
|
receiverContent.replaceAll(TENANT_DOMAIN_PROPERTY,tenantDomain.toLowerCase());
|
|
|
|
streamList.add(streamContent);
|
|
|
|
streamList.add(receiverContent);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return streamList;
|
|
|
|
return streamList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -507,6 +519,15 @@ public class DeviceTypePublisherAdminServiceImpl implements DeviceTypePublisherA
|
|
|
|
SSLContext.setDefault(sslContext);
|
|
|
|
SSLContext.setDefault(sslContext);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void cleanup(Stub stub) {
|
|
|
|
|
|
|
|
if (stub != null) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
stub.cleanup();
|
|
|
|
|
|
|
|
} catch (AxisFault axisFault) {
|
|
|
|
|
|
|
|
//do nothing
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|