Skip to content

Commit

Permalink
addition of the instance uuid from describe sensor response from the CC.
Browse files Browse the repository at this point in the history
clean up of the instance usage and creation event/listeners
  • Loading branch information
kedwards3 committed Sep 19, 2012
1 parent dc104a3 commit c99ac8b
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 282 deletions.
Expand Up @@ -22,23 +22,26 @@

import java.io.StringReader;
import java.util.ArrayList;
import java.util.Date;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.log4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;

import com.eucalyptus.auth.Accounts;
import com.eucalyptus.auth.AuthException;
import com.eucalyptus.cluster.Clusters;
import com.eucalyptus.records.Logs;
import com.eucalyptus.entities.Entities;
import com.eucalyptus.event.ListenerRegistry;
import com.eucalyptus.reporting.event.InstanceUsageEvent;
import com.eucalyptus.util.LogUtil;
import com.eucalyptus.util.async.BroadcastCallback;
import com.eucalyptus.vm.VmInstance;
import com.eucalyptus.vm.VmInstances;
import com.eucalyptus.ws.util.SerializationUtils;

import com.google.common.collect.Lists;

Expand Down Expand Up @@ -108,17 +111,12 @@ public void fireException(Throwable e) {

@Override
public void fire(DescribeSensorsResponse msg) {

try {

//Document sensorDoc = loadXMLFromString(msg.toString());

//sensorDoc.get
// TODO : Need to fire the correct usage events to the domain model
try {

for (SensorsResourceType sensorData : msg.getSensorsResources()) {
LOG.debug("sensorData.getResourceName() : "
+ sensorData.getResourceName());
for (SensorsResourceType sensorData : msg.getSensorsResources()) {
String resourceName = sensorData.getResourceName();
String resourceUuid = sensorData.getResourceUuid();

for (MetricsResourceType metricType : sensorData.getMetrics()) {
LOG.debug("sensorData.getMetrics() : "
Expand All @@ -137,65 +135,39 @@ public void fire(DescribeSensorsResponse msg) {
.getValues()) {
// fire constructed event to the domain model
// Need real uuid from describe sensors.

ListenerRegistry
.getInstance()
.fireEvent(
new com.eucalyptus.reporting.event.InstanceUsageEvent(
String.valueOf(sensorData
.hashCode()),
System.currentTimeMillis(),
sensorData
.getResourceName(),
metricType
.getMetricName(),
Integer.parseInt(counterType
.getSequenceNum()
.toString()),
dimensionType
.getDimensionName(),
valueType.getValue()
,
Long.getLong(valueType
.getTimestamp()
.toString())));

final long valueTimeStamp = valueType.getTimestamp().getTime();
if (!resourceUuid.isEmpty()
&& !resourceName.isEmpty()) {
ListenerRegistry
.getInstance()
.fireEvent(
new com.eucalyptus.reporting.event.InstanceUsageEvent(
resourceUuid,
System.currentTimeMillis(),
resourceName,
metricType
.getMetricName(),
Integer.parseInt(counterType
.getSequenceNum()
.toString()),
dimensionType
.getDimensionName(),
valueType
.getValue(),
valueTimeStamp));


}
}
}
}
}
}


} catch (Exception ex) {
LOG.debug("Unable to fire describe sensors call back", ex);

}
}

private static Document loadXMLFromString(String xml) throws Exception
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
InputSource is = new InputSource(new StringReader(xml));
return builder.parse(is);
}

private InstanceUsageEvent buildInstanceUsageEvent(Document sensorsDoc) {

String uuid = sensorsDoc.getElementsByTagName("uuid").item(0).getNodeValue();
String timestamp = sensorsDoc.getElementsByTagName("timestamp").item(0).getNodeValue();
String resourceName = sensorsDoc.getElementsByTagName("resourceName").item(0).getNodeValue();
String metric = sensorsDoc.getElementsByTagName("metric").item(0).getNodeValue();
String sequenceNum = sensorsDoc.getElementsByTagName("sequenceNum").item(0).getNodeValue();
String dimension;
Double value;
long valueTimestamp;



Element TIMESTAMP = sensorsDoc.getElementById("timestamp");

return null; // new InstanceUsageEvent(UUID.getNodeValue(),TIMESTAMP.getNodeValue(), );
}

}
Expand Up @@ -289,6 +289,7 @@ public class DescribeSensorsResponse extends CloudClusterMessage {
public class SensorsResourceType extends EucalyptusData {
String resourceName;
String resourceType;
String resourceUuid;

ArrayList<MetricsResourceType> metrics = new ArrayList<MetricsResourceType>();

Expand Down
3 changes: 2 additions & 1 deletion clc/modules/msgs/src/main/resources/cc-sensors.xml
Expand Up @@ -58,7 +58,8 @@
<mapping class="edu.ucsb.eucalyptus.msgs.SensorsResourceType"
abstract="true">
<value name="resourceName" field="resourceName" type="java.lang.String" />
<value name="resourceType" field="resourceType" type="java.lang.String" />
<value name="resourceType" field="resourceType" type="java.lang.String" />
<value name="resourceUuid" field="resourceUuid" type="java.lang.String" />
<collection field="metrics"
factory="org.jibx.runtime.Utility.arrayListFactory">
<structure name="metrics"
Expand Down
Expand Up @@ -45,6 +45,7 @@ public static String generateReport( @Nonnull final String type,
null );
} catch ( final Exception e ) {
throw new ReportGenerationException( "Error generating report", e );

}

return new String( reportOutput.toByteArray(), Charsets.UTF_8 );
Expand Down
Expand Up @@ -91,7 +91,6 @@ public ReportArtEntity generateReportArt(ReportArtEntity report)
*/
Map<String,InstanceArtEntity> instanceEntities = new HashMap<String,InstanceArtEntity>();
/*
Iterator iter = wrapper.scanWithNativeQuery( "scanInstanceCreateEvents" );
while (iter.hasNext()) {
ReportingInstanceCreateEvent createEvent = (ReportingInstanceCreateEvent) iter.next();
Expand Down Expand Up @@ -143,7 +142,11 @@ public ReportArtEntity generateReportArt(ReportArtEntity report)
}
InstanceUsageArtEntity usage = instance.getUsage();
>>>>>>> team/clc-dev/reporting
Add usage to totals, and update average cpu
if (lastEvent != null) {
long lastMs = lastEvent.getTimestampMs();
Expand All @@ -157,6 +160,9 @@ public ReportArtEntity generateReportArt(ReportArtEntity report)
- Math.max(report.getBeginMs(),lastEvent.getTimestampMs());
usage.setDurationMs(usage.getDurationMs()+timeMs);
<<<<<<< HEAD
Add usage to totals
=======
<<<<<<< HEAD
/* Interpolate and add usage to totals
Expand All @@ -165,6 +171,7 @@ public ReportArtEntity generateReportArt(ReportArtEntity report)
subtract(usageEvent.getCumulativeDiskIoMegs(),
lastEvent.getCumulativeDiskIoMegs()));
>>>>>>> team/clc-dev/reporting
usage.setDiskIoMegs(
interpolate(report.getBeginMs(), report.getEndMs(), lastMs,
usageEvent.getTimestampMs(), rawValue));
Expand Down Expand Up @@ -237,8 +244,8 @@ public ReportArtEntity generateReportArt(ReportArtEntity report)
} //while
*/

*/
/* Perform totals and summations
*/
for (String zoneName : report.getZones().keySet()) {
Expand Down Expand Up @@ -277,7 +284,7 @@ private static void updateUsageTotals(UsageTotalsArtEntity totals, InstanceArtEn

totalEntity.addDurationMs(newEntity.getDurationMs());

/* Update total average for this zone, cluster, etc, based upon instance average */
/* Update total average for this zone, cluster, etc, based upon instance average
if (totalEntity.getCpuPercentAvg() == null && newEntity.getCpuPercentAvg() != null) {
totalEntity.setCpuPercentAvg(newEntity.getCpuPercentAvg());
totalEntity.addDurationMs(newEntity.getDurationMs());
Expand All @@ -288,7 +295,7 @@ private static void updateUsageTotals(UsageTotalsArtEntity totals, InstanceArtEn
totalEntity.setCpuPercentAvg(newWeightedAverage);
}
/* Add megs from this instance to totals for zone, cluster, etc */
Add megs from this instance to totals for zone, cluster, etc
totalEntity.setDiskIoMegs(
plus(totalEntity.getDiskIoMegs(),
newEntity.getDiskIoMegs()));
Expand All @@ -313,7 +320,7 @@ private static void updateUsageTotals(UsageTotalsArtEntity totals, InstanceArtEn
totalEntity.setInstanceCnt(totalEntity.getInstanceCnt()+1);
/* Update total running time and type count for this instance type */
Update total running time and type count for this instance type
Map<String,InstanceUsageArtEntity> typeTotals = totals.getTypeTotals();
if (!typeTotals.containsKey(instance.getInstanceType().toLowerCase())) {
typeTotals.put(instance.getInstanceType().toLowerCase(),
Expand All @@ -323,7 +330,7 @@ private static void updateUsageTotals(UsageTotalsArtEntity totals, InstanceArtEn
typeTotals.get(instance.getInstanceType().toLowerCase());
typeTotal.setInstanceCnt(typeTotal.getInstanceCnt()+1);
typeTotal.setDurationMs(typeTotal.getDurationMs() + totalEntity.getDurationMs());
typeTotal.setDurationMs(typeTotal.getDurationMs() + totalEntity.getDurationMs());*/
}

/**
Expand Down
Expand Up @@ -24,7 +24,6 @@

import org.hibernate.annotations.Entity;


@Entity
@javax.persistence.Entity
@SqlResultSetMapping(name = "createEventMap", entities = @EntityResult(entityClass = ReportingInstanceCreateEvent.class))
Expand Down
Expand Up @@ -42,8 +42,6 @@ public class ReportingInstanceUsageEvent

@Column(name="uuid", nullable=false)
protected String uuid;
@Column(name="timestamp", nullable=true)
protected Long timestamp;
@Column(name="resource_name", nullable=true)
protected String resourceName;
@Column(name="metric", nullable=true)
Expand All @@ -61,6 +59,7 @@ public class ReportingInstanceUsageEvent

protected ReportingInstanceUsageEvent()
{

}

ReportingInstanceUsageEvent(final String uuid, final long timestamp, final String resourceName,
Expand All @@ -76,7 +75,7 @@ protected ReportingInstanceUsageEvent()
assertThat(value, notNullValue());
assertThat(valueTimestamp, notNullValue());
this.uuid = uuid;
this.timestamp = timestamp;
this.timestampMs = timestamp;
this.resourceName = resourceName;
this.metric = metric;
this.sequenceNum = sequenceNum;
Expand All @@ -97,10 +96,6 @@ public String getUuid() {
return uuid;
}

public Long getTimestamp() {
return timestamp;
}

public String getResourceName() {
return resourceName;
}
Expand All @@ -127,53 +122,11 @@ public Long getValueTimestamp() {

@Override
public String toString() {
return "ReportingInstanceUsageEvent [uuid=" + uuid + ", timestamp="
+ timestamp + ", resourceName=" + resourceName
+ ", metric=" + metric + ", sequenceNum=" + sequenceNum
+ ", dimension=" + dimension + ", value=" + value
+ ", valueTimestamp=" + valueTimestamp + "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result
+ ((dimension == null) ? 0 : dimension.hashCode());
result = prime * result + sequenceNum;
result = prime * result
+ ((timestamp == null) ? 0 : timestamp.hashCode());
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ReportingInstanceUsageEvent other = (ReportingInstanceUsageEvent) obj;
if (dimension == null) {
if (other.dimension != null)
return false;
} else if (!dimension.equals(other.dimension))
return false;
if (sequenceNum != other.sequenceNum)
return false;
if (timestamp == null) {
if (other.timestamp != null)
return false;
} else if (!timestamp.equals(other.timestamp))
return false;
if (uuid == null) {
if (other.uuid != null)
return false;
} else if (!uuid.equals(other.uuid))
return false;
return true;
return "ReportingInstanceUsageEvent [uuid=" + uuid
+ ", resourceName=" + resourceName + ", metric=" + metric
+ ", sequenceNum=" + sequenceNum + ", dimension="
+ dimension + ", value=" + value + ", valueTimestamp="
+ valueTimestamp + "]";
}

}

0 comments on commit c99ac8b

Please sign in to comment.