Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Adam Kučera
semanticBMS
Commits
9017ec17
Commit
9017ec17
authored
Jan 29, 2018
by
Adam Kučera
Browse files
"rough" implementation of the data access API completed
the REST endpoint is not correctly specified and the provider is not tested
parent
58980706
Changes
15
Hide whitespace changes
Inline
Side-by-side
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/DataPointsEndpoint.java
View file @
9017ec17
...
...
@@ -52,7 +52,7 @@ public class DataPointsEndpoint {
logger
.
debug
(
json
);
AddressRequest
readSpecs
=
m
.
readValue
(
json
,
AddressRequest
.
class
);
logger
.
debug
(
readSpecs
);
SnapshotResponse
result
=
dc
.
getDataPointValues
(
readSpecs
,
allowCache
(
cache
));
SnapshotResponse
result
=
new
SnapshotResponse
(
dc
.
getDataPointValues
(
readSpecs
,
allowCache
(
cache
))
)
;
logger
.
debug
(
result
);
return
result
;
}
catch
(
IOException
e
)
{
...
...
@@ -78,7 +78,7 @@ public class DataPointsEndpoint {
logger
.
debug
(
json
);
AddressRequest
readSpecs
=
m
.
readValue
(
json
,
AddressRequest
.
class
);
logger
.
debug
(
readSpecs
);
return
dc
.
getDataPointsAggregation
(
readSpecs
,
agg
,
allowCache
(
cache
));
return
new
AggregateResponse
(
dc
.
getDataPointsAggregation
(
readSpecs
,
agg
,
allowCache
(
cache
))
)
;
}
catch
(
IOException
e
)
{
return
AggregateResponse
.
getErrorResponse
(
"Unable to parse query:"
+
e
);
}
...
...
@@ -99,7 +99,7 @@ public class DataPointsEndpoint {
logger
.
debug
(
json
);
GroupedAddressRequest
readSpecs
=
m
.
readValue
(
json
,
GroupedAddressRequest
.
class
);
logger
.
debug
(
readSpecs
);
return
dc
.
getDataPointGroupedValues
(
readSpecs
,
allowCache
(
cache
));
return
new
SnapshotResponse
(
dc
.
getDataPointGroupedValues
(
readSpecs
,
allowCache
(
cache
))
)
;
}
catch
(
IOException
e
)
{
return
SnapshotResponse
.
getErrorResponse
(
"Unable to parse query:"
+
e
);
}
...
...
@@ -120,7 +120,7 @@ public class DataPointsEndpoint {
logger
.
debug
(
json
);
GroupedAddressRequest
readSpecs
=
m
.
readValue
(
json
,
GroupedAddressRequest
.
class
);
logger
.
debug
(
readSpecs
);
AggregateResponse
result
=
dc
.
getDataPointGroupAggregations
(
readSpecs
,
agg
,
allowCache
(
cache
));
AggregateResponse
result
=
new
AggregateResponse
(
dc
.
getDataPointGroupAggregations
(
readSpecs
,
agg
,
allowCache
(
cache
))
)
;
logger
.
debug
(
result
);
return
result
;
}
catch
(
IOException
e
)
{
...
...
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/TrendsEndpoint.java
View file @
9017ec17
...
...
@@ -21,7 +21,7 @@ import com.fasterxml.jackson.databind.JsonMappingException;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
cz.muni.fi.lasaris.sbms.data.api.request.GroupedAddressRequest
;
import
cz.muni.fi.lasaris.sbms.data.api.request.Trend
s
Request
;
import
cz.muni.fi.lasaris.sbms.data.api.request.TrendRequest
;
import
cz.muni.fi.lasaris.sbms.data.api.request.AddressRequest
;
import
cz.muni.fi.lasaris.sbms.data.api.response.AggregateResponse
;
import
cz.muni.fi.lasaris.sbms.data.api.response.SeriesOfSlicesResponse
;
...
...
@@ -31,7 +31,6 @@ import cz.muni.fi.lasaris.sbms.data.api.response.SliceResponse;
import
cz.muni.fi.lasaris.sbms.data.api.response.TrendResponse
;
import
cz.muni.fi.lasaris.sbms.data.api.response.ValueResponse
;
import
cz.muni.fi.lasaris.sbms.data.entities.Address
;
import
cz.muni.fi.lasaris.sbms.data.entities.AddressGroup
;
import
cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction
;
import
cz.muni.fi.lasaris.sbms.data.entities.AggregationWindow
;
import
cz.muni.fi.lasaris.sbms.data.entities.Interpolation
;
...
...
@@ -40,6 +39,7 @@ import cz.muni.fi.lasaris.sbms.data.entities.containers.Aggregation;
import
cz.muni.fi.lasaris.sbms.data.entities.containers.Series
;
import
cz.muni.fi.lasaris.sbms.data.entities.containers.Slice
;
import
cz.muni.fi.lasaris.sbms.data.entities.containers.Trend
;
import
cz.muni.fi.lasaris.sbms.data.entities.containers.TrendGroup
;
import
cz.muni.fi.lasaris.sbms.data.entities.values.AggregatedValue
;
import
cz.muni.fi.lasaris.sbms.data.entities.values.InterpolatedValue
;
import
cz.muni.fi.lasaris.sbms.data.logic.TrendsDataCollector
;
...
...
@@ -72,7 +72,7 @@ public class TrendsEndpoint {
)
{
try
{
Trend
s
Request
r
=
getReadSpecsSingle
(
id
,
start
,
end
,
null
,
null
,
null
,
null
,
null
);
TrendRequest
r
=
getReadSpecsSingle
(
id
,
start
,
end
,
null
,
null
,
null
,
null
,
null
);
Trend
v
=
dc
.
getTrend
(
r
);
return
new
TrendResponse
(
v
);
}
catch
(
Exception
e
)
{
...
...
@@ -94,7 +94,7 @@ public class TrendsEndpoint {
)
{
try
{
Trend
s
Request
r
=
getReadSpecsSingle
(
id
,
timestamp
,
timestamp
,
samplingCron
,
samplingDur
,
interpolation
,
null
,
null
);
TrendRequest
r
=
getReadSpecsSingle
(
id
,
timestamp
,
timestamp
,
samplingCron
,
samplingDur
,
interpolation
,
null
,
null
);
InterpolatedValue
v
=
dc
.
getValue
(
r
);
return
new
ValueResponse
(
v
);
}
catch
(
Exception
e
)
{
...
...
@@ -116,7 +116,7 @@ public class TrendsEndpoint {
@QueryParam
(
"sampling.interpolation"
)
Interpolation
interpolation
)
{
try
{
Trend
s
Request
r
=
getReadSpecsSingle
(
id
,
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
null
,
null
);
TrendRequest
r
=
getReadSpecsSingle
(
id
,
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
null
,
null
);
Trend
v
=
dc
.
getTrend
(
r
);
return
new
TrendResponse
(
v
);
}
catch
(
Exception
e
)
{
...
...
@@ -136,7 +136,7 @@ public class TrendsEndpoint {
@QueryParam
(
"aggregation.function"
)
AggregationFunction
aggregation
)
{
try
{
Trend
s
Request
r
=
getReadSpecsSingle
(
id
,
start
,
end
,
null
,
null
,
null
,
aggregation
,
null
);
TrendRequest
r
=
getReadSpecsSingle
(
id
,
start
,
end
,
null
,
null
,
null
,
aggregation
,
null
);
AggregatedValue
v
=
dc
.
getAggregate
(
r
);
return
new
ValueResponse
(
v
);
}
catch
(
Exception
e
)
{
...
...
@@ -159,7 +159,7 @@ public class TrendsEndpoint {
@QueryParam
(
"aggregation.duration"
)
Long
windowDur
)
{
try
{
Trend
s
Request
r
=
getReadSpecsSingle
(
id
,
start
,
end
,
windowCron
,
windowDur
,
null
,
aggregation
,
window
);
TrendRequest
r
=
getReadSpecsSingle
(
id
,
start
,
end
,
windowCron
,
windowDur
,
null
,
aggregation
,
window
);
Trend
v
=
dc
.
getTrend
(
r
);
return
new
TrendResponse
(
v
);
}
catch
(
Exception
e
)
{
...
...
@@ -178,7 +178,7 @@ public class TrendsEndpoint {
@QueryParam
(
"timestamp"
)
String
timestamp
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
timestamp
,
timestamp
,
null
,
null
,
null
,
null
,
null
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
timestamp
,
timestamp
,
null
,
null
,
null
,
null
,
null
);
Slice
v
=
dc
.
getSlice
(
r
);
return
new
SliceResponse
(
v
);
}
catch
(
Exception
e
)
{
...
...
@@ -198,9 +198,9 @@ public class TrendsEndpoint {
@QueryParam
(
"aggregation.function"
)
AggregationFunction
aggregation
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
timestamp
,
timestamp
,
null
,
null
,
null
,
null
,
null
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
timestamp
,
timestamp
,
null
,
null
,
null
,
null
,
null
);
if
(
grouping
)
{
Aggregation
<
AddressGroup
>
v
=
dc
.
getGroupedAggregatesForSlice
(
r
);
Map
<
String
,
AggregatedValue
>
v
=
dc
.
getGroupedAggregatesForSlice
(
r
);
return
new
AggregateResponse
(
v
);
}
else
{
AggregatedValue
v
=
dc
.
getAggregateForSlice
(
r
);
...
...
@@ -224,9 +224,9 @@ public class TrendsEndpoint {
@QueryParam
(
"end"
)
String
end
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
null
,
null
,
null
,
null
,
null
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
null
,
null
,
null
,
null
,
null
);
if
(
grouping
)
{
Map
<
String
,
Map
<
Address
,
Trend
>
>
v
=
dc
.
getGroupedTrends
(
r
);
Map
<
String
,
TrendGroup
>
v
=
dc
.
getGroupedTrends
(
r
);
return
new
SetOfTrendsResponse
(
v
,
true
);
}
else
{
Map
<
Address
,
Trend
>
v
=
dc
.
getTrends
(
r
);
...
...
@@ -250,9 +250,9 @@ public class TrendsEndpoint {
@QueryParam
(
"aggregation.function"
)
AggregationFunction
aggregation
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
null
,
null
,
null
,
aggregation
,
null
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
null
,
null
,
null
,
aggregation
,
null
);
if
(
grouping
)
{
Map
<
String
,
Aggregation
<
Address
>>
v
=
dc
.
getGroupedAggregates
(
r
);
Map
<
String
,
Map
<
Address
,
AggregatedValue
>>
v
=
dc
.
getGroupedAggregates
(
r
);
return
new
SetOfAggregatesResponse
(
v
);
}
else
{
Aggregation
<
Address
>
v
=
dc
.
getAggregates
(
r
);
...
...
@@ -276,9 +276,9 @@ public class TrendsEndpoint {
@QueryParam
(
"aggregation.function"
)
AggregationFunction
aggregation
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
null
,
null
,
null
,
aggregation
,
null
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
null
,
null
,
null
,
aggregation
,
null
);
if
(
grouping
)
{
Aggregation
<
AddressGroup
>
v
=
dc
.
getGroupedTrendsAggregate
(
r
);
Map
<
String
,
AggregatedValue
>
v
=
dc
.
getGroupedTrendsAggregate
(
r
);
return
new
AggregateResponse
(
v
);
}
else
{
AggregatedValue
v
=
dc
.
getTrendsAggregate
(
r
);
...
...
@@ -304,9 +304,9 @@ public class TrendsEndpoint {
@QueryParam
(
"sampling.interpolation"
)
Interpolation
interpolation
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
null
,
null
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
null
,
null
);
if
(
grouping
)
{
Map
<
String
,
Map
<
Address
,
Trend
>
>
v
=
dc
.
getGroupedTrends
(
r
);
Map
<
String
,
TrendGroup
>
v
=
dc
.
getGroupedTrends
(
r
);
return
new
SetOfTrendsResponse
(
v
,
true
);
}
else
{
Map
<
Address
,
Trend
>
v
=
dc
.
getTrends
(
r
);
...
...
@@ -332,7 +332,7 @@ public class TrendsEndpoint {
@QueryParam
(
"sampling.interpolation"
)
Interpolation
interpolation
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
null
,
null
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
null
,
null
);
if
(
grouping
)
{
Map
<
String
,
Series
<
Slice
>>
v
=
dc
.
getGroupedSeriesOfSlices
(
r
);
return
new
SeriesOfSlicesResponse
(
v
);
...
...
@@ -362,7 +362,7 @@ public class TrendsEndpoint {
@QueryParam
(
"aggregation.function"
)
AggregationFunction
aggregation
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
aggregation
,
null
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
aggregation
,
null
);
if
(
grouping
)
{
Map
<
String
,
Trend
>
v
=
dc
.
getGroupedSeriesOfAggregates
(
r
);
return
new
TrendResponse
(
v
);
...
...
@@ -392,9 +392,9 @@ public class TrendsEndpoint {
@QueryParam
(
"aggregation.duration"
)
Long
windowDur
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
windowCron
,
windowDur
,
null
,
aggregation
,
window
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
windowCron
,
windowDur
,
null
,
aggregation
,
window
);
if
(
grouping
)
{
Map
<
String
,
Map
<
Address
,
Trend
>
>
v
=
dc
.
getGroupedTrends
(
r
);
Map
<
String
,
TrendGroup
>
v
=
dc
.
getGroupedTrends
(
r
);
return
new
SetOfTrendsResponse
(
v
,
true
);
}
else
{
Map
<
Address
,
Trend
>
v
=
dc
.
getTrends
(
r
);
...
...
@@ -421,7 +421,7 @@ public class TrendsEndpoint {
@QueryParam
(
"aggregation.duration"
)
Long
windowDur
)
{
try
{
Trend
s
Request
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
windowCron
,
windowDur
,
null
,
aggregation
,
window
);
TrendRequest
r
=
getReadSpecsMulti
(
ids
,
grouping
,
start
,
end
,
windowCron
,
windowDur
,
null
,
aggregation
,
window
);
if
(
grouping
)
{
Map
<
String
,
Trend
>
v
=
dc
.
getGroupedWindowedTrendsAggregate
(
r
);
return
new
TrendResponse
(
v
);
...
...
@@ -460,17 +460,17 @@ public class TrendsEndpoint {
*/
private
Trend
s
Request
getReadSpecsSingle
(
String
id
,
String
start
,
String
end
,
String
samplingCron
,
private
TrendRequest
getReadSpecsSingle
(
String
id
,
String
start
,
String
end
,
String
samplingCron
,
Long
samplingDur
,
Interpolation
interpolation
,
AggregationFunction
aggregation
,
AggregationWindow
window
)
{
Trend
s
Request
readSpecs
=
getReadSpecsBase
(
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
aggregation
,
window
);
TrendRequest
readSpecs
=
getReadSpecsBase
(
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
aggregation
,
window
);
readSpecs
.
setAddressSpecs
(
new
Address
(
id
));
return
readSpecs
;
}
private
Trend
s
Request
getReadSpecsMulti
(
String
json
,
boolean
grouping
,
String
start
,
String
end
,
String
samplingCron
,
private
TrendRequest
getReadSpecsMulti
(
String
json
,
boolean
grouping
,
String
start
,
String
end
,
String
samplingCron
,
Long
samplingDur
,
Interpolation
interpolation
,
AggregationFunction
aggregation
,
AggregationWindow
window
)
throws
JsonParseException
,
JsonMappingException
,
IOException
{
Trend
s
Request
readSpecs
=
getReadSpecsBase
(
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
aggregation
,
window
);
TrendRequest
readSpecs
=
getReadSpecsBase
(
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
aggregation
,
window
);
if
(
grouping
)
{
readSpecs
.
setAddressSpecs
(
m
.
readValue
(
json
,
AddressRequest
.
class
));
}
else
{
...
...
@@ -480,12 +480,12 @@ public class TrendsEndpoint {
}
private
Trend
s
Request
getReadSpecsBase
(
String
start
,
String
end
,
String
samplingCron
,
private
TrendRequest
getReadSpecsBase
(
String
start
,
String
end
,
String
samplingCron
,
Long
samplingDur
,
Interpolation
interpolation
,
AggregationFunction
aggregation
,
AggregationWindow
window
)
{
Trend
s
Request
readSpecs
=
new
Trend
s
Request
();
TrendRequest
readSpecs
=
new
TrendRequest
();
SeriesSpecs
s
=
getSeriesSpecs
(
start
,
end
,
samplingCron
,
samplingDur
,
interpolation
,
aggregation
,
window
);
readSpecs
.
setSeriesSpecs
(
s
);
readSpecs
.
setAggregation
(
aggregation
,
window
);
readSpecs
.
setAggregation
(
aggregation
);
return
readSpecs
;
}
...
...
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/request/Trend
s
Request.java
→
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/request/TrendRequest.java
View file @
9017ec17
...
...
@@ -4,43 +4,59 @@ import java.util.Arrays;
import
cz.muni.fi.lasaris.sbms.data.entities.Address
;
import
cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction
;
import
cz.muni.fi.lasaris.sbms.data.entities.AggregationWindow
;
import
cz.muni.fi.lasaris.sbms.data.entities.SeriesSpecs
;
public
class
Trend
s
Request
{
public
class
TrendRequest
{
private
AddressRequest
ar
;
private
GroupedAddressRequest
gar
;
private
SeriesSpecs
s
;
private
AggregationFunction
af
;
public
Address
getAddress
()
{
// TODO Auto-generated method stub
return
null
;
return
ar
.
getAddresses
().
get
(
0
);
}
public
void
setSeriesSpecs
(
SeriesSpecs
s
)
{
// TODO Auto-generated method stub
this
.
s
=
s
;
}
public
void
setAggregation
(
AggregationFunction
aggregation
,
AggregationWindow
window
)
{
// TODO Auto-generated method stub
public
void
setAggregation
(
AggregationFunction
aggregation
)
{
this
.
af
=
aggregation
;
}
public
void
setAddressSpecs
(
Address
a
)
{
AddressRequest
ar
=
new
AddressRequest
();
ar
.
setAddresses
(
Arrays
.
asList
(
new
Address
[]
{
a
}));
setAddressSpecs
(
ar
);
}
public
void
setAddressSpecs
(
AddressRequest
ar
)
{
// TODO Auto-generated method stub
this
.
ar
=
ar
;
}
public
void
setAddressSpecs
(
GroupedAddressRequest
readValue
)
{
// TODO Auto-generated method stub
public
void
setAddressSpecs
(
GroupedAddressRequest
gar
)
{
this
.
gar
=
gar
;
}
public
AddressRequest
getAddressSpecs
()
{
return
this
.
ar
;
}
public
GroupedAddressRequest
getGroupedAddressSpecs
()
{
return
this
.
gar
;
}
public
SeriesSpecs
getSeriesSpecs
()
{
return
this
.
s
;
}
public
AggregationFunction
getAggregation
()
{
return
this
.
af
;
}
public
boolean
isGropuing
()
{
return
this
.
gar
!=
null
;
}
}
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SetOfAggregatesResponse.java
View file @
9017ec17
...
...
@@ -2,7 +2,6 @@ package cz.muni.fi.lasaris.sbms.data.api.response;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
cz.muni.fi.lasaris.sbms.data.entities.Address
;
import
cz.muni.fi.lasaris.sbms.data.entities.containers.Aggregation
;
...
...
@@ -27,7 +26,11 @@ public class SetOfAggregatesResponse {
private
SetOfAggregatesResponse
()
{
this
.
results
=
null
;
}
public
SetOfAggregatesResponse
(
Map
<
String
,
Map
<
Address
,
AggregatedValue
>>
data
)
{
this
.
results
=
data
;
}
/*
public SetOfAggregatesResponse(Map<String, Aggregation<Address>> data) {
this.results = new LinkedHashMap<String, Map<Address, AggregatedValue>>();
for(Entry<String, Aggregation<Address>> e : data.entrySet()) {
...
...
@@ -36,7 +39,7 @@ public class SetOfAggregatesResponse {
this.results.put(e.getKey(), a);
}
}
*/
public
SetOfAggregatesResponse
(
Address
a
,
AggregatedValue
v
)
{
this
.
results
=
new
LinkedHashMap
<
String
,
Map
<
Address
,
AggregatedValue
>>();
...
...
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/api/response/SetOfTrendsResponse.java
View file @
9017ec17
...
...
@@ -2,9 +2,11 @@ package cz.muni.fi.lasaris.sbms.data.api.response;
import
java.util.LinkedHashMap
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
cz.muni.fi.lasaris.sbms.data.entities.Address
;
import
cz.muni.fi.lasaris.sbms.data.entities.containers.Trend
;
import
cz.muni.fi.lasaris.sbms.data.entities.containers.TrendGroup
;
public
class
SetOfTrendsResponse
{
private
static
final
String
DEFAULT_GROUPING
=
"noGrouping"
;
...
...
@@ -26,18 +28,29 @@ public class SetOfTrendsResponse {
this
.
results
=
null
;
}
/*
public SetOfTrendsResponse(Map<String, Map<Address, Trend>> data, boolean groups) {
this.results = data;
}
*/
public
SetOfTrendsResponse
(
Map
<
String
,
TrendGroup
>
data
,
boolean
groups
)
{
this
.
results
=
new
LinkedHashMap
<
String
,
Map
<
Address
,
Trend
>>();
for
(
Entry
<
String
,
TrendGroup
>
e
:
data
.
entrySet
())
{
Map
<
Address
,
Trend
>
a
=
new
LinkedHashMap
<
Address
,
Trend
>();
e
.
getValue
().
forEach
((
k
,
v
)
->
a
.
put
(
k
,
v
));
this
.
results
.
put
(
e
.
getKey
(),
a
);
}
}
public
SetOfTrendsResponse
(
Map
<
Address
,
Trend
>
data
)
{
this
.
results
=
new
LinkedHashMap
<
String
,
Map
<
Address
,
Trend
>>();
this
.
results
.
put
(
DEFAULT_GROUPING
,
data
);
}
public
SetOfTrendsResponse
(
Address
a
,
Trend
v
)
{
this
(
new
LinkedHashMap
<
String
,
Map
<
Address
,
Trend
>>()
,
true
)
;
this
.
results
=
new
LinkedHashMap
<
String
,
Map
<
Address
,
Trend
>>();
this
.
results
.
put
(
DEFAULT_GROUPING
,
new
LinkedHashMap
<
Address
,
Trend
>());
this
.
results
.
get
(
DEFAULT_GROUPING
).
put
(
a
,
v
);
}
...
...
DataAccessAPI/src/main/java/cz/muni/fi/lasaris/sbms/data/logic/DPDataCollector.java
View file @
9017ec17
package
cz.muni.fi.lasaris.sbms.data.logic
;
import
java.util.Collections
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.NavigableMap
;
import
java.util.NavigableSet
;
import
java.util.Properties
;
import
java.util.concurrent.atomic.AtomicInteger
;
import
org.apache.log4j.Logger
;
import
cz.muni.fi.lasaris.sbms.data.api.request.GroupedAddressRequest
;
import
cz.muni.fi.lasaris.sbms.data.api.request.AddressRequest
;
import
cz.muni.fi.lasaris.sbms.data.api.response.AggregateResponse
;
import
cz.muni.fi.lasaris.sbms.data.api.response.SnapshotResponse
;
import
cz.muni.fi.lasaris.sbms.data.entities.Address
;
import
cz.muni.fi.lasaris.sbms.data.entities.AggregationFunction
;
import
cz.muni.fi.lasaris.sbms.data.entities.containers.Snapshot
;
import
cz.muni.fi.lasaris.sbms.data.entities.values.AggregatedValue
;
import
cz.muni.fi.lasaris.sbms.data.entities.values.RawValue
;
import
cz.muni.fi.lasaris.sbms.data.util.Aggregator
;
import
cz.muni.fi.lasaris.sbms.data.providers.AbstractSimpleDataPointsProvider
;
import
cz.muni.fi.lasaris.sbms.data.providers.DataPointsProvider
;
public
class
DPDataCollector
{
final
static
Logger
logger
=
Logger
.
getLogger
(
DPDataCollector
.
class
);
public
SnapshotResponse
getDataPointValues
(
AddressRequest
readSpecs
,
boolean
allowCache
)
{
return
new
SnapshotResponse
(
getDataPointValuesSnapshot
(
readSpecs
,
allowCache
));
public
Snapshot
getDataPointValues
(
AddressRequest
readSpecs
,
boolean
allowCache
)
{
DataPointsProvider
p
=
new
MultiProtocolProvider
(
new
ProtocolParser
(
readSpecs
));
Snapshot
result
=
p
.
getDataPointValues
(
readSpecs
.
getAddresses
(),
allowCache
);
return
result
;
}
private
Snapshot
getDataPointValuesSnapshot
(
AddressRequest
readSpecs
,
boolean
allowCache
)
{
NavigableMap
<
String
,
AddressRequest
>
protocols
=
readSpecs
.
getProtocols
();
if
(
protocols
.
size
()
==
1
)
{
return
ProviderManager
.
getDataPointsProvider
(
protocols
.
firstKey
())
.
getDataPointValues
(
protocols
.
get
(
protocols
.
firstKey
()).
getAddresses
(),
allowCache
);
}
AtomicInteger
counter
=
new
AtomicInteger
(
0
);
int
count
=
protocols
.
keySet
().
size
();
List
<
Snapshot
>
results
=
Collections
.
synchronizedList
(
new
LinkedList
<
Snapshot
>());
for
(
String
protocol
:
protocols
.
keySet
())
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Snapshot
rs
=
(
ProviderManager
.
getDataPointsProvider
(
protocol
)
.
getDataPointValues
(
protocols
.
get
(
protocol
).
getAddresses
(),
allowCache
));
synchronized
(
results
)
{
results
.
add
(
rs
);
counter
.
incrementAndGet
();
results
.
notifyAll
();
}
}}).
start
();
}
synchronized
(
results
)
{
while
(
counter
.
get
()
<
count
)
{
try
{
results
.
wait
();
}
catch
(
InterruptedException
e
)
{
logger
.
error
(
"Exception while waiting for completion."
,
e
);
}
}
}
Snapshot
result
=
new
Snapshot
();
synchronized
(
results
)
{
for
(
Snapshot
r
:
results
)
{
result
.
addAll
(
r
.
getData
());
}
}
public
AggregatedValue
getDataPointsAggregation
(
AddressRequest
readSpecs
,
AggregationFunction
aggregation
,
boolean
allowCache
)
{
DataPointsProvider
p
=
new
MultiProtocolProvider
(
new
ProtocolParser
(
readSpecs
));
AggregatedValue
result
=
p
.
getDataPointsAggregation
(
readSpecs
.
getAddresses
(),
aggregation
,
allowCache
);
return
result
;
}
public
AggregateResponse
getDataPointsAggregation
(
AddressRequest
readSpecs
,
AggregationFunction
aggregation
,
public
Map
<
String
,
Snapshot
>
getDataPointGroupedValues
(
GroupedAddressRequest
readSpecs
,
boolean
allowCache
)
{
NavigableMap
<
String
,
AddressRequest
>
protocols
=
readSpecs
.
getProtocols
();
if
(
protocols
.
size
()
==
1
)
{
return
new
AggregateResponse
(
ProviderManager
.
getDataPointsProvider
(
protocols
.
firstKey
())
.
getDataPointsAggregation
(
protocols
.
get
(
protocols
.
firstKey
()).
getAddresses
(),
aggregation
,
allowCache
));
}
Snapshot
data
=
getDataPointValuesSnapshot
(
readSpecs
,
allowCache
);
return
new
AggregateResponse
(
computeAggregation
(
data
.
getData
(),
aggregation
));
DataPointsProvider
p
=
new
MultiProtocolProvider
(
new
ProtocolParser
(
readSpecs
));
Map
<
String
,
Snapshot
>
result
=
p
.
getDataPointGroupedValues
(
readSpecs
.
getGroups
(),
allowCache
);
return
result
;
}
public
SnapshotResponse
getDataPointGroupedValues
(
GroupedAddressRequest
readSpecs
,
boolean
allowCache
)
{
return
new
SnapshotResponse
(
getDataPointGroupedValuesMap
(
readSpecs
,
allowCache
));
public
Map
<
String
,
AggregatedValue
>
getDataPointGroupAggregations
(
GroupedAddressRequest
readSpecs
,
AggregationFunction
aggregation
,
boolean
allowCache
)
{
DataPointsProvider
p
=
new
MultiProtocolProvider
(
new
ProtocolParser
(
readSpecs
));
Map
<
String
,
AggregatedValue
>
result
=
p
.
getDataPointGroupAggregations
(
readSpecs
.
getGroups
(),
aggregation
,
allowCache
);
return
result
;
}
private
Map
<
String
,
Snapshot
>
getDataPointGroupedValuesMap
(
GroupedAddressRequest
readSpecs
,
boolean
allowCache
)
{
NavigableMap
<
String
,
GroupedAddressRequest
>
protocols
=
readSpecs
.
getProtocols
();
if
(
protocols
.
size
()
==
1
)
{
return
ProviderManager
.
getDataPointsProvider
(
protocols
.
firstKey
())
.
getDataPointGroupedValues
(
protocols
.
get
(
protocols
.
firstKey
()).
getGroups
(),
allowCache
);
}
AtomicInteger
counter
=
new
AtomicInteger
(
0
);
int
count
=
protocols
.
keySet
().
size
();
private
class
MultiProtocolProvider
extends
AbstractSimpleDataPointsProvider
{
List
<
SnapshotResponse
>
results
=
Collections
.
synchronizedList
(
new
LinkedList
<
SnapshotResponse
>())
;
ProtocolParser
p
;
for
(
String
protocol
:
protocols
.
keySet
())
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
SnapshotResponse
rs
=
new
SnapshotResponse
(
ProviderManager
.
getDataPointsProvider
(
protocol
).
getDataPointGroupedValues
(
protocols
.
get
(
protocol
).
getGroups
(),
allowCache
));
synchronized
(
results
)
{
results
.
add
(
rs
);
counter
.
incrementAndGet
();
results
.
notifyAll
();
}
}}).
start
();
public
MultiProtocolProvider
(
ProtocolParser
parser
)
{
p
=
parser
;
}
synchronized
(
results
)
{