Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.metadata/
/GUI/target/
318 changes: 0 additions & 318 deletions .metadata/.log

This file was deleted.

Binary file removed .metadata/.mylyn/tasks.xml.zip
Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions .metadata/.plugins/org.eclipse.jdt.ui/dialog_settings.xml

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5 changes: 0 additions & 5 deletions .metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml

This file was deleted.

11 changes: 11 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Microservices-Shop</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
32 changes: 32 additions & 0 deletions Decision-Service/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
28 changes: 28 additions & 0 deletions Decision-Service/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Decision-Service-Ste</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.springframework.ide.eclipse.boot.validation.springbootbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
4 changes: 4 additions & 0 deletions Decision-Service/.settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding/<project>=UTF-8
9 changes: 9 additions & 0 deletions Decision-Service/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
4 changes: 4 additions & 0 deletions Decision-Service/.settings/org.eclipse.m2e.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
boot.validation.initialized=true
eclipse.preferences.version=1
7 changes: 7 additions & 0 deletions Decision-Service/HELP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Getting Started

### Reference Documentation
For further reference, please consider the following sections:

* [Official Apache Maven documentation](https://maven.apache.org/guides/index.html)

File renamed without changes.
File renamed without changes.
11 changes: 8 additions & 3 deletions demo/pom.xml → Decision-Service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<artifactId>Decision-Service-Ste</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<name>decisionService</name>
<description>Ste is trying his best</description>

<properties>
<java.version>1.8</java.version>
Expand All @@ -23,6 +23,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.example.DecisionServiceSte;

import java.util.Hashtable;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* @author Stefano Lugli;
*/
@RestController
public class BIOS { // basic input output service (nice joke i know)
Hashtable<String, Hashtable<String, ServiceDetailsRequestModel>> availableServices = new Hashtable<String, Hashtable<String, ServiceDetailsRequestModel>>();
/*
* Using HASHTABLES for thread safety
* This hastable uses the groupid of each service as key. The vlues is itself an hastable composed of every sensor
* that is part of the group. Its key will be the services' name and its value the ServiceDetailsRequestModel
*/

@Autowired
public BIOS()
{
// TODO servicesHistory = new File("servicesHistory.JSON"); //Used just for
// personal Info
// or maybe a tiny data base
}

@PostConstruct
public void init()
{
// possible TODO The surveillance thread used to check the correct services
// updates will be starting from here
// Not sure if i actually do need this
}

@GetMapping(value = "get-available-services", produces = "application/json")
public String getConnectionsInfo()
{
JSONObject returnValue = new JSONObject();

for(String key : availableServices.keySet()) {
//Iterate through all the groups
JSONObject thisGroupValue = new JSONObject();
Hashtable<String, ServiceDetailsRequestModel> groupAvailableServices = availableServices.get(key);
for(String key2 : groupAvailableServices.keySet())
//Iterate trough all the services in a group
thisGroupValue.put(key2, groupAvailableServices.get(key2).getServiceData());
//Key2 is the service name
returnValue.put(key, thisGroupValue);
//key is the groupID
}
return returnValue.toString();
}

@PutMapping(value = "put", produces = "application/json") // update services data
public String updateService(@RequestParam(value = "serviceName") String serviceName, @RequestBody ServiceDetailsRequestModel requestServiceDetails)
{
System.out.println(requestServiceDetails.getServiceData());
if(requestServiceDetails.isClosed() == true) { //TODO check if using delete mapping may be better
try {
availableServices.get(requestServiceDetails.getGroupID()).remove(serviceName);
if(availableServices.get(requestServiceDetails.getGroupID()).size() == 0) // IF the group is empty
availableServices.remove(requestServiceDetails.getGroupID()); //delete it from the map!
return "ok";
} catch(NullPointerException e) {
return "error";
}
}
Hashtable<String, ServiceDetailsRequestModel> groupAvailableServices;
try{
groupAvailableServices = availableServices.get(requestServiceDetails.getGroupID());
//The group is already available in the services list
}catch(NullPointerException e){
System.out.print(e);
System.out.println(" won't be able to use this service's informations!");
return "error";
}
try {
groupAvailableServices.put(serviceName, requestServiceDetails);
}catch (NullPointerException e) {
//It'd mean there is no hashtable for that groupID
groupAvailableServices = new Hashtable<String, ServiceDetailsRequestModel>();
//The group is not available in the services list, so we create a new one
availableServices.put(requestServiceDetails.getGroupID(), groupAvailableServices);
//And add it to the services list!
groupAvailableServices.put(serviceName, requestServiceDetails);
}

String returnValue = requestServiceDetails.getType().compareToIgnoreCase("sensor") == 0
? new String(requestServiceDetails.toString()) // Returning the same string may be used to check that the communcation was correct!
: DecisionMaker.takeDecision(requestServiceDetails, groupAvailableServices); // The way decision will be hadnled may vary
// TODO availableServices.get(serviceName); //Write the old ServiceName's value
// in the service history.
System.out.print("Put request for service status update from: ");
System.out.println(serviceName);
System.out.println("Answer: " + returnValue);
return returnValue;
}

// @GetMapping("get-history") TODO -> will return the services requests history
// since a given date
// The get mapping may be used by any kind of service or by the GUI
@PreDestroy
public void destroy() {
// servicesHistory.close(); files do not close... ?
// surveillance_thread.join(); (or kill it brutally who cares)
// TODO close all the services
}
}
Loading