diff --git a/modules/samples/connectedlap/component/agent/pom.xml b/modules/samples/connectedlap/component/agent/pom.xml index d4cbf265..7df6e310 100644 --- a/modules/samples/connectedlap/component/agent/pom.xml +++ b/modules/samples/connectedlap/component/agent/pom.xml @@ -19,7 +19,7 @@ - connectedlap + connectedlap-component org.wso2 1.0.0-SNAPSHOT ../pom.xml diff --git a/modules/samples/connectedlap/component/laptopagent/dependency-reduced-pom.xml b/modules/samples/connectedlap/component/laptopagent/dependency-reduced-pom.xml deleted file mode 100644 index 7eb4bccc..00000000 --- a/modules/samples/connectedlap/component/laptopagent/dependency-reduced-pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - 4.0.0 - org.wso2.agent - connectedlap - connectedlap - 1.0 - http://maven.apache.org - - ConnectedLap - - - maven-eclipse-plugin - 2.9 - - true - false - - - - maven-compiler-plugin - 2.3.2 - - ${jdk.version} - ${jdk.version} - - - - maven-jar-plugin - - - **/log4j.properties - - - - true - org.wso2.agent.main.JavaApp - dependency-jars/ - - - ${project.build.directory}/../../../feature/feature/src/main/resources/agent/ - - - - maven-dependency-plugin - 2.5.1 - - - copy-dependencies - package - - copy-dependencies - - - runtime - ${project.build.directory}/dependency-jars/ - - - - - - maven-shade-plugin - 2.3 - - - package - - shade - - - - - org.wso2.agent.main.JavaApp - - - - - - - - - - - junit - junit - 3.8.1 - test - - - commons-logging - commons-logging - 1.1.1 - provided - - - - 1.7 - - - diff --git a/modules/samples/connectedlap/component/laptopagent/pom.xml b/modules/samples/connectedlap/component/laptopagent/pom.xml index e87c3ebc..cca5f756 100644 --- a/modules/samples/connectedlap/component/laptopagent/pom.xml +++ b/modules/samples/connectedlap/component/laptopagent/pom.xml @@ -1,7 +1,7 @@ 4.0.0 - org.wso2.agent + org.wso2 connectedlap jar 1.0 diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/common/Common.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/common/Common.java index e3d1930e..23399889 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/common/Common.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/common/Common.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.common; import java.security.GeneralSecurityException; diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/config/Configuration.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/config/Configuration.java index 8fa74724..5e132560 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/config/Configuration.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/config/Configuration.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.config; import java.io.FileInputStream; diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/datasense/PushSystemUsage.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/datasense/PushSystemUsage.java index daebcceb..df4560b4 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/datasense/PushSystemUsage.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/datasense/PushSystemUsage.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.datasense; import java.io.IOException; diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/main/JavaApp.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/main/JavaApp.java index de8af893..f101605a 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/main/JavaApp.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/main/JavaApp.java @@ -1,6 +1,25 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.main; import java.io.BufferedReader; +import java.io.Console; import java.io.File; import java.io.InputStreamReader; import java.util.ArrayList; @@ -18,99 +37,101 @@ import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; -/** - * Created by amila on 5/17/16. - */ public class JavaApp { - - final static int TIMEINTERVAL=10000;//ms - public static String SUPASSWORD=""; - static int TIMECOUNTER=0;// 5 minute interval sender tracker; + + final static int TIMEINTERVAL = 10000;//ms + public static String SUPASSWORD = ""; + static int TIMECOUNTER = 0;// 5 minute interval sender tracker; public static String deviceid; - + public static void main(String args[]) { - - BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + System.out.println("Enter Super User Password"); - System.out.print("Enter Password:"); - try{ - JavaApp.SUPASSWORD = String.valueOf(br.readLine()); - }catch(Exception e){ - System.out.println("Retreving Password Failed!"); - }finally{ - try{ - br.close(); - }catch(Exception e){} + BufferedReader br = null; + try { + Console console = System.console(); + //String username = console.readLine("Username: "); + char[] password = console.readPassword("Password: "); + JavaApp.SUPASSWORD = String.valueOf(password); + + //br = new BufferedReader(new InputStreamReader(System.in)); + //JavaApp.SUPASSWORD = String.valueOf(br.readLine()); + } catch (Exception e) { + System.out.println("Retrieving Password Failed!"); + } finally { + try { + br.close(); + } catch (Exception e) { + } } - - if(!new Configuration().checkRegistered()){ - SystemSpec spec=new Monitor().getSysInfo(JavaApp.SUPASSWORD); - String devicetoken=new String(); - String devicerefreshtoken=new String(); - Configuration config=new Configuration(); - try { - String token=String.valueOf(config.getInitProperty("auth-token")); - //token="9c7a1b4d6625cdd936b894cc0e7c7390"; - String refreshtoken=String.valueOf(config.getInitProperty("refresh-token")); - String device_name=String.valueOf(config.getInitProperty("device-name")); - Client client = Client.create(Common.configureClient()); - client.setConnectTimeout(50000); - WebResource webResource = client.resource("https://localhost:9443/CONNECTEDLAP/device/register"); + + if (!new Configuration().checkRegistered()) { + SystemSpec spec = new Monitor().getSysInfo(JavaApp.SUPASSWORD); + String devicetoken = new String(); + String devicerefreshtoken = new String(); + Configuration config = new Configuration(); + try { + String token = String.valueOf(config.getInitProperty("auth-token")); + //token="9c7a1b4d6625cdd936b894cc0e7c7390"; + String refreshtoken = String.valueOf(config.getInitProperty("refresh-token")); + String device_name = String.valueOf(config.getInitProperty("device-name")); + Client client = Client.create(Common.configureClient()); + client.setConnectTimeout(50000); + WebResource webResource = client.resource("https://localhost:9443/CONNECTEDLAP/device/register"); String mac = spec.getMacaddress().replaceAll("\\:", ""); deviceid = mac; - String request="{" - + "\"owner\":\"admin\"," - +"\"deviceId\":\""+mac+"\"," - +"\"deviceName\": \""+device_name+"\"," - +"\"discSpace\":"+spec.getStorage()+"," - +"\"memory\":"+spec.getRamsize()+"," - +"\"cpuInfo\":\""+spec.getProcessor_speed()+"\"," - + "\"networkType\":\""+spec.getNetworktype()+"\"," - +"\"cpucorecount\":\""+spec.getProcessor_cores()+"\"" - + "}"; - - ClientResponse response = (ClientResponse)webResource.type("application/json").header("Authorization", "Bearer "+token).post(ClientResponse.class,request); - System.out.println("Output from Server .... \n"); - String output = (String)response.getEntity(String.class); - System.out.println(output); - JSONObject outputJson= new JSONObject(output); - devicetoken=outputJson.getString("accessToken"); - devicerefreshtoken=outputJson.getString("refreshToken"); - if (response.getStatus() != 200) { - throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); - } - config.SaveRegistration(spec,devicetoken,devicerefreshtoken); - } - catch (Exception e) { - //e.printStackTrace(); - throw e; - } - - } - //String deviceid=String.valueOf(new Configuration().getProperty("deviceid")); - String owner=String.valueOf(new Configuration().getInitProperty("owner")); - String devicetoken=String.valueOf(new Configuration().getProperty("devicetoken")); - String devicerefreshtoken=String.valueOf(new Configuration().getProperty("devicerefreshtoken")); - - while(true) { + String request = "{" + + "\"owner\":\"admin\"," + + "\"deviceId\":\"" + mac + "\"," + + "\"deviceName\": \"" + device_name + "\"," + + "\"discSpace\":" + spec.getStorage() + "," + + "\"memory\":" + spec.getRamsize() + "," + + "\"cpuInfo\":\"" + spec.getProcessor_speed() + "\"," + + "\"networkType\":\"" + spec.getNetworktype() + "\"," + + "\"cpucorecount\":\"" + spec.getProcessor_cores() + "\"" + + "}"; + + ClientResponse response = (ClientResponse) webResource.type("application/json").header("Authorization", "Bearer " + token).post(ClientResponse.class, request); + System.out.println("Output from Server .... \n"); + String output = (String) response.getEntity(String.class); + System.out.println(output); + JSONObject outputJson = new JSONObject(output); + devicetoken = outputJson.getString("accessToken"); + devicerefreshtoken = outputJson.getString("refreshToken"); + if (response.getStatus() != 200) { + throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); + } + config.SaveRegistration(spec, devicetoken, devicerefreshtoken); + } catch (Exception e) { + //e.printStackTrace(); + throw e; + } + + } + //String deviceid=String.valueOf(new Configuration().getProperty("deviceid")); + String owner = String.valueOf(new Configuration().getInitProperty("owner")); + String devicetoken = String.valueOf(new Configuration().getProperty("devicetoken")); + String devicerefreshtoken = String.valueOf(new Configuration().getProperty("devicerefreshtoken")); + + while (true) { try { new RecordStore().saveData(new Monitor().getSysUsage(JavaApp.SUPASSWORD)); - JavaApp.TIMECOUNTER+=TIMEINTERVAL; - if(JavaApp.TIMECOUNTER>=10000){ - ArrayList sysUsageList=new RecordStore().readData(); - for (SystemUsage systemUsage : sysUsageList) { - new PushSystemUsage().pushData(systemUsage,deviceid,owner,devicetoken); - } - File file = new File("usagelog"); - if(file.delete()){ - System.out.println(file.getName() + " is deleted!"); - }else{ - System.out.println("Delete operation is failed."); - } + JavaApp.TIMECOUNTER += TIMEINTERVAL; + if (JavaApp.TIMECOUNTER >= 10000) { + ArrayList sysUsageList = new RecordStore().readData(); + for (SystemUsage systemUsage : sysUsageList) { + new PushSystemUsage().pushData(systemUsage, deviceid, owner, devicetoken); + } + File file = new File("usagelog"); + if (file.delete()) { + System.out.println(file.getName() + " is deleted!"); + } else { + System.out.println("Delete operation is failed."); + } } Thread.sleep(JavaApp.TIMEINTERVAL); - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); } } diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/Monitor.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/Monitor.java index 8bbedc8b..2a958bd9 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/Monitor.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/Monitor.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.resourcemonitor; import org.wso2.agent.resourcemonitor.infocollector.Collector; diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/exception/OperationalException.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/exception/OperationalException.java index 6542a74a..464f6989 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/exception/OperationalException.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/exception/OperationalException.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.resourcemonitor.exception; @SuppressWarnings("serial") diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/infocollector/Collector.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/infocollector/Collector.java index a137010f..ca798686 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/infocollector/Collector.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/infocollector/Collector.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.resourcemonitor.infocollector; import javax.management.OperationsException; diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/pojo/SystemSpec.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/pojo/SystemSpec.java index f826599a..0fb90fdc 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/pojo/SystemSpec.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/pojo/SystemSpec.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.resourcemonitor.pojo; public class SystemSpec { diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/pojo/SystemUsage.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/pojo/SystemUsage.java index 460dc5be..b539a912 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/pojo/SystemUsage.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/resourcemonitor/pojo/SystemUsage.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.resourcemonitor.pojo; public class SystemUsage { diff --git a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/store/RecordStore.java b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/store/RecordStore.java index 57ecb44d..ec5ce718 100644 --- a/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/store/RecordStore.java +++ b/modules/samples/connectedlap/component/laptopagent/src/main/java/org/wso2/agent/store/RecordStore.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.agent.store; import java.io.BufferedReader;