This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85c8cdd
commit 3c74ba9
Showing
6 changed files
with
316 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
console/src/main/scripts/plugins/metrics/ts/hawkularDatamining.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/// | ||
/// Copyright 2015-2016 Red Hat, Inc. and/or its affiliates | ||
/// and other contributors as indicated by the @author tags. | ||
/// | ||
/// Licensed 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. | ||
/// | ||
|
||
/// <reference path="metricsPlugin.ts"/> | ||
/// <reference path="../../includes.ts"/> | ||
|
||
module HawkularMetrics { | ||
|
||
_module.provider('HawkularDatamining', function() { | ||
this.setProtocol = function(protocol) { | ||
this.protocol = protocol; | ||
return this; | ||
}; | ||
|
||
|
||
this.setHost = function(host) { | ||
this.host = host; | ||
return this; | ||
}; | ||
|
||
this.setPort = function(port) { | ||
this.port = 8080; | ||
return this; | ||
}; | ||
|
||
this.$get = ['$resource', '$location', function($resource, $location) { | ||
|
||
this.setProtocol(this.protocol || $location.protocol() || 'http'); | ||
this.setHost(this.host || $location.host() || 'localhost'); | ||
this.setPort(this.port || $location.port() || '8080'); | ||
|
||
var prefix = this.protocol + '://' + this.host + ':' + this.port; | ||
var predictionUrlPart = '/hawkular/datamining'; | ||
var url = prefix + predictionUrlPart; | ||
var factory: any = {}; | ||
|
||
|
||
factory.Predict = function(tenantId) { | ||
return $resource(url + '/models/:metricId/predict', null, { | ||
predict: { | ||
method: 'GET', | ||
isArray: true, | ||
params: {ahead: '1'}, | ||
headers: {'Hawkular-Tenant': tenantId} | ||
} | ||
}); | ||
}; | ||
|
||
factory.formatPredictedData = function(data): IChartDataPoint[] { | ||
function convertBytesToMegaBytes(bytes:number):number { | ||
return bytes / 1024 / 1024; | ||
} | ||
|
||
// The schema is different for bucketed output | ||
return _.map(data, (point:IChartDataPoint) => { | ||
|
||
//point.timestamp = currentTimestamp; | ||
|
||
return { | ||
timestamp: point.timestamp, | ||
date: new Date(point.timestamp), | ||
value: convertBytesToMegaBytes(point.value), | ||
avg: convertBytesToMegaBytes(point.value), | ||
min: 0, | ||
max: 0, | ||
percentile95th: 0, | ||
median: 0, | ||
empty: false | ||
}; | ||
}); | ||
}; | ||
|
||
return factory; | ||
}]; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
modules/end-to-end-test/src/test/groovy/org/hawkular/integration/test/DataminingITest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright 2015-2016 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed 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.hawkular.integration.test | ||
import org.hawkular.inventory.api.model.Metric | ||
import org.hawkular.inventory.api.model.MetricDataType | ||
import org.hawkular.inventory.api.model.MetricType | ||
import org.hawkular.inventory.api.model.MetricUnit | ||
import org.junit.Assert | ||
import org.junit.BeforeClass | ||
import org.junit.Test | ||
|
||
import static org.junit.Assert.assertEquals | ||
|
||
class DataminingITest extends AbstractTestBase { | ||
|
||
private static final String invBasePath = "/hawkular/inventory" | ||
private static final String dtmBasePath = "/hawkular/datamining" | ||
|
||
private static final String predictionRelationshipName = "__inPrediction" | ||
|
||
private static final String environmentId = "test" | ||
private static final String feedId = "itest-dtm-feed" | ||
private static final String metricTypeId = "itest-dtm-mt" | ||
private static final String metricId = "itest-dtm-m" | ||
|
||
private static String tenantId; | ||
|
||
@BeforeClass | ||
public static void setUpData() { | ||
|
||
def payload = null; | ||
def response = null | ||
String path = "/hawkular/inventory/environments/$environmentId"; | ||
int attemptCount = 5; | ||
int delay = 500; | ||
for (int i = 0; i < attemptCount; i++) { | ||
try { | ||
response = client.get(path: path) | ||
/* all is well, we can leave the loop */ | ||
break; | ||
} catch (groovyx.net.http.HttpResponseException e) { | ||
/* some initial attempts may fail */ | ||
} | ||
println "'$path' not ready yet, about to retry after $delay ms" | ||
/* sleep one second */ | ||
Thread.sleep(delay); | ||
} | ||
if (response.status != 200) { | ||
Assert.fail("Getting path '$path' returned status ${response.status}, tried $attemptCount times"); | ||
} | ||
assertEquals(environmentId, response.data.id) | ||
|
||
String path2 = "/hawkular/inventory/tenant" | ||
for (int i = 0; i < attemptCount; i++) { | ||
try { | ||
response = client.get(path: path2) | ||
/* all is well, we can leave the loop */ | ||
break; | ||
} catch (groovyx.net.http.HttpResponseException e) { | ||
/* some initial attempts may fail */ | ||
} | ||
println "'$path2' not ready yet, about to retry after $delay ms" | ||
/* sleep one second */ | ||
Thread.sleep(delay); | ||
} | ||
if (response.status != 200) { | ||
Assert.fail("Getting path '$path2' returned status ${response.status}, tried $attemptCount times"); | ||
} | ||
tenantId = response.data.id | ||
|
||
|
||
/** | ||
* Create Feed | ||
*/ | ||
payload = [ | ||
id: "$feedId".toString() | ||
] | ||
response = client.post(path: "$invBasePath/feeds", body: payload) | ||
assertEquals(201, response.status) | ||
|
||
/** | ||
* Create metricType | ||
*/ | ||
def metricType = MetricType.Blueprint.builder(MetricDataType.GAUGE) | ||
.withId(metricTypeId).withUnit(MetricUnit.BYTES).withInterval(2000).build() | ||
response = client.post(path: "$invBasePath/feeds/$feedId/metricTypes", body: metricType) | ||
assertEquals(201, response.status) | ||
|
||
/** | ||
* Create metric | ||
*/ | ||
def metric = Metric.Blueprint.builder().withId(metricId).withMetricTypePath(metricTypeId).build() | ||
response = client.post(path: "$invBasePath/feeds/$feedId/metrics", body: metric) | ||
assertEquals(201, response.status) | ||
|
||
/** | ||
* Create prediction relationship | ||
*/ | ||
payload = [ | ||
name: "$predictionRelationshipName".toString(), | ||
source: "/t;$tenantId".toString(), | ||
target: "/t;$tenantId/f;$feedId/m;$metricId".toString() | ||
] | ||
response = client.post(path: "$invBasePath/tenants/relationships", body: payload) | ||
assertEquals(201, response.status) | ||
|
||
|
||
Thread.sleep(2000); | ||
} | ||
|
||
|
||
@Test | ||
public void testModelExists() { | ||
def response = client.get(path: "$dtmBasePath/models/$metricId", headers: ["Hawkular-Tenant": tenantId]) | ||
assertEquals(200, response.status) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.