Skip to content
Closed
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/com/cloud/offering/DiskOffering.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ public String toString() {

public ProvisioningType getProvisioningType();

public void setProvisioningType(ProvisioningType provisioningType);

public String getTags();

public String[] getTagsArray();
Expand Down
6 changes: 6 additions & 0 deletions engine/schema/src/com/cloud/storage/DiskOfferingVO.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import javax.persistence.Transient;

import com.cloud.offering.DiskOffering;
import com.cloud.storage.Storage.ProvisioningType;
import com.cloud.utils.db.GenericDao;

@Entity
Expand Down Expand Up @@ -353,6 +354,11 @@ public Storage.ProvisioningType getProvisioningType(){
return provisioningType;
}

@Override
public void setProvisioningType(ProvisioningType provisioningType) {
this.provisioningType = provisioningType;
}

@Override
public long getDiskSize() {
return diskSize;
Expand Down
4 changes: 4 additions & 0 deletions engine/schema/src/com/cloud/upgrade/dao/VersionDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
// under the License.
package com.cloud.upgrade.dao;

import java.util.List;

import com.cloud.upgrade.dao.VersionVO.Step;
import com.cloud.utils.db.GenericDao;

public interface VersionDao extends GenericDao<VersionVO, Long> {
VersionVO findByVersion(String version, Step step);

String getCurrentVersion();

List<VersionVO> getAllVersions();
}
9 changes: 9 additions & 0 deletions engine/schema/src/com/cloud/upgrade/dao/VersionDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,13 @@ public String getCurrentVersion() {
}

}

@Override
@DB
public List<VersionVO> getAllVersions() {
SearchCriteria<VersionVO> sc = AllFieldsSearch.create();
sc.setParameters("step", "Complete");

return listBy(sc);
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
<cs.jasypt.version>1.9.2</cs.jasypt.version>
<cs.trilead.version>1.0.0-build217</cs.trilead.version>
<cs.ehcache.version>2.6.9</cs.ehcache.version>
<cs.gson.version>1.7.2</cs.gson.version>
<cs.guava-testlib.version>18.0</cs.guava-testlib.version>
<cs.gson.version>[2.4,)</cs.gson.version>
<cs.guava.version>18.0</cs.guava.version>
<cs.xapi.version>6.2.0-3.1</cs.xapi.version>
<cs.httpclient.version>4.5</cs.httpclient.version>
Expand Down
20 changes: 20 additions & 0 deletions reporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# CloudStack Usage Report

This directory contains the CloudStack reporter webservice used by the Apache CloudStack project
to gather anonymous statistical information about CloudStack deployments.

Since version 4.7 the management server sends out a anonymized Usage Report out to the
project every 7 days.

This information is used to gain information about how CloudStack is being used.

Turning this Usage Reporting functionality off can be done in the Global Settings by setting
'usage.report.interval' to 0.

For more information visit http://cloudstack.apache.org/call-home.html

# The webservice
The Python Flask application in this directory is the webservice running on https://reporting.cloudstack.apache.org/report
and stores all the incoming information in a ElasticSearch database.

Since Apache CloudStack is Open Source we show not only how we generate the report, but also how we process it.
64 changes: 64 additions & 0 deletions reporter/usage-report-collector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF 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.

from flask import abort, Flask, request, Response
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good work i would say, but just add some comments on this service purpose, may be for people seeing it later can understand it easily. Any reason to have this service written in python and other usage code to run along with cs in java?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This service will not run in the mgmt server. It is where the data is being send. Users will not deploy this, it will be running on call-home.cloudstack.org

from elasticsearch import Elasticsearch
import json
import time

def json_response(response):
return json.dumps(response, indent=2) + "\n", 200, {'Content-Type': 'application/json; charset=utf-8'}

def generate_app(config=None):
app = Flask(__name__)

@app.route('/report', methods=['POST'])
def report():
# We expect JSON data, so if the Content-Type doesn't match we throw an error
if 'Content-Type' in request.headers:
if request.headers['Content-Type'] != 'application/json':
abort(417, "No or incorrect Content-Type header was supplied")

index = "cloudstack-%s" % time.strftime("%Y.%m.%d", time.gmtime())
timestamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime())

es = Elasticsearch()
es.indices.create(index=index, ignore=400)

report = json.loads(request.data)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be we wanted to add a small check to see report is None and proceed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, although Flask will catch exceptions and generate HTTP errors based on those

report["timestamp"] = timestamp

es.index(index=index, doc_type="usage-report", body=json.dumps(report),
timestamp=timestamp, refresh=True)

response = {}
return json_response(response)

return app


app = generate_app()

# Only run the App if this script is invoked from a Shell
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=8088)

# Otherwise provide a variable called 'application' for mod_wsgi
else:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this application var used? Its not global var as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is for mod_wsgi. It will read "app" and run the application from there

application = app
10 changes: 10 additions & 0 deletions server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@
<artifactId>opensaml</artifactId>
<version>${cs.opensaml.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${cs.gson.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${cs.guava.version}</version>
</dependency>
</dependencies>
<build>
<testResources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@

<bean id="statsCollector" class="com.cloud.server.StatsCollector" />

<bean id="usageReporter" class="org.apache.cloudstack.report.UsageReporter" />

<bean id="storagePoolAutomationImpl" class="com.cloud.storage.StoragePoolAutomationImpl" />

<bean id="domainManagerImpl" class="com.cloud.user.DomainManagerImpl" />
Expand Down
48 changes: 48 additions & 0 deletions server/src/org/apache/cloudstack/report/AtomicGsonAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF 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.apache.cloudstack.report;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.google.common.util.concurrent.AtomicLongMap;
import java.util.Map;
import java.io.IOException;

public class AtomicGsonAdapter extends TypeAdapter<AtomicLongMap> {

public AtomicLongMap<Object> read(JsonReader reader) throws IOException {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @wido,
Why don't you turn this method "void", so you could remove the "return null;" line.

reader.nextNull();
return null;
}

public void write(JsonWriter writer, AtomicLongMap value) throws IOException {
if (value == null) {
writer.nullValue();
return;
}

@SuppressWarnings("unchecked")
Map <String, Long> map = value.asMap();

writer.beginObject();
for (Map.Entry<String, Long> entry : map.entrySet()) {
writer.name(entry.getKey()).value(entry.getValue());
}
writer.endObject();
}
}
Loading