1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 package org.ogf.graap.wsag.server.accounting;
36
37 import java.text.DecimalFormat;
38 import java.text.MessageFormat;
39
40 import org.apache.log4j.Logger;
41 import org.ogf.graap.wsag4j.types.engine.CompensationType;
42 import org.ogf.graap.wsag4j.types.engine.GuaranteeEvaluationResultType;
43 import org.ogf.graap.wsag4j.types.engine.SLAMonitoringNotificationEventType;
44 import org.ogf.graap.wsag4j.types.engine.SLOEvaluationResultType;
45
46
47
48
49
50
51
52 public class SimpleAccountingSystemLogger implements IAccountingSystem
53 {
54
55 private static final Logger LOG = Logger.getLogger( SimpleAccountingSystemLogger.class );
56
57
58
59
60
61
62
63 public void issueCompensation( SLAMonitoringNotificationEventType notificationEvent )
64 {
65
66 for ( GuaranteeEvaluationResultType evaluationResult : notificationEvent.getGuaranteeEvaluationResultArray() )
67 {
68 LOG.info( MessageFormat.format( "evaluation result for guarantee ''{0}'': {1}",
69 new Object[] { evaluationResult.getName(), evaluationResult.getType() } ) );
70
71 if ( evaluationResult.isSetCompensation() )
72 {
73 LOG.info( MessageFormat.format( "issue compensation for guarantee ''{0}''",
74 new Object[] { evaluationResult.getName() } ) );
75 logCompensation( evaluationResult.getCompensation(), evaluationResult.getType() );
76 }
77 else
78 {
79 LOG.info( MessageFormat.format( "no compensation issued for guarantee ''{0}''",
80 new Object[] { evaluationResult.getName() } ) );
81 }
82 }
83
84 }
85
86 private void logCompensation( CompensationType compensation, SLOEvaluationResultType.Enum type )
87 {
88
89 String compensationType = "";
90
91 switch ( type.intValue() )
92 {
93 case SLOEvaluationResultType.INT_SLO_FULFILLED:
94 compensationType = "reward";
95 break;
96 case SLOEvaluationResultType.INT_SLO_VIOLATED:
97 compensationType = "penalty";
98 break;
99 default:
100 compensationType = "unsupported result";
101 }
102
103 long value = compensation.getValue().longValue();
104 String unit = ( compensation.isSetUnit() ) ? compensation.getUnit() : "";
105
106 DecimalFormat twoDForm = new DecimalFormat( "#.##" );
107 String formatedValue = twoDForm.format( value );
108
109 LOG.info( MessageFormat.format( "{0}: {1} {2}", new Object[] { compensationType, formatedValue, unit } ) );
110 }
111
112 }