View Javadoc

1   /* 
2    * Copyright (c) 2007, Fraunhofer-Gesellschaft
3    * All rights reserved.
4    * 
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are
7    * met:
8    * 
9    * (1) Redistributions of source code must retain the above copyright
10   *     notice, this list of conditions and the disclaimer at the end.
11   *     Redistributions in binary form must reproduce the above copyright
12   *     notice, this list of conditions and the following disclaimer in
13   *     the documentation and/or other materials provided with the
14   *     distribution.
15   * 
16   * (2) Neither the name of Fraunhofer nor the names of its
17   *     contributors may be used to endorse or promote products derived
18   *     from this software without specific prior written permission.
19   * 
20   * DISCLAIMER
21   * 
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33   *  
34   */
35  package org.ogf.graap.wsag.api.sla;
36  
37  import org.ogf.graap.wsag.api.pattern.AdvanceReservationPattern;
38  import org.ogf.graap.wsag4j.types.scheduling.TimeConstraintType;
39  import org.ogf.schemas.graap.wsAgreement.AgreementTemplateType;
40  
41  //@formatter:off
42  /**
43   * AdvanceReservationComputeJobTemplate
44   * 
45   * <pre>
46   * {@code
47   * <wsag:AgreementTemplateType wsag:TemplateId="1"
48   *     xmlns:wsag="http://schemas.ggf.org/graap/2007/03/ws-agreement">
49   *     <wsag:Name>ADVANCE-RESERVATION-COMPUTE-JOB</wsag:Name>
50   *     <wsag:Context>
51   *         <wsag:ServiceProvider>AgreementResponder</wsag:ServiceProvider>
52   *         <wsag:TemplateId>1</wsag:TemplateId>
53   *         <wsag:TemplateName>ADVANCE-RESERVATION-COMPUTE-JOB</wsag:TemplateName>
54   *     </wsag:Context>
55   *     <wsag:Terms>
56   *         <wsag:All>
57   *             <wsag:ExactlyOne>
58   *                 <wsag:ServiceDescriptionTerm wsag:Name="APPLICATION_SDT"
59   *                     wsag:ServiceName="COMPUTE_SERVICE">
60   *                     <jsdl:JobDefinition xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl">
61   *                         <jsdl:JobDescription>
62   *                             <jsdl:Application>
63   *                                 <jsdl:ApplicationName>Application_1</jsdl:ApplicationName>
64   *                                 <jsdl:ApplicationVersion>1</jsdl:ApplicationVersion>
65   *                                 <jsdl:Description>Description</jsdl:Description>
66   *                             </jsdl:Application>
67   *                         </jsdl:JobDescription>
68   *                     </jsdl:JobDefinition>
69   *                 </wsag:ServiceDescriptionTerm>
70   *                 <wsag:ServiceDescriptionTerm wsag:Name="APPLICATION_SDT"
71   *                     wsag:ServiceName="COMPUTE_SERVICE">
72   *                     <jsdl:JobDefinition xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl">
73   *                         <jsdl:JobDescription>
74   *                             <jsdl:Application>
75   *                                 <jsdl:ApplicationName>Application_2</jsdl:ApplicationName>
76   *                                 <jsdl:ApplicationVersion>2</jsdl:ApplicationVersion>
77   *                                 <jsdl:Description>Description</jsdl:Description>
78   *                             </jsdl:Application>
79   *                         </jsdl:JobDescription>
80   *                     </jsdl:JobDefinition>
81   *                 </wsag:ServiceDescriptionTerm>
82   *             </wsag:ExactlyOne>
83   *             <wsag:ServiceDescriptionTerm wsag:Name="RESOURCE_SDT"
84   *                 wsag:ServiceName="RESOURCE_PROVISIONING_SERVICE">
85   *                 <jsdl:JobDefinition xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl">
86   *                     <jsdl:JobDescription>
87   *                         <jsdl:Resources>
88   *                             <jsdl:IndividualCPUTime>
89   *                                 <jsdl:Exact>
90   *                                     $RESOURCES.getIndividualCPUTime().getExactArray(0).
91   *                                     getDoubleValue()</jsdl:Exact>
92   *                             </jsdl:IndividualCPUTime>
93   *                             <jsdl:IndividualCPUCount>
94   *                                 <jsdl:Exact>
95   *                                     $RESOURCES.getIndividualCPUCount().getExactArray(0).
96   *                                     getDoubleValue()</jsdl:Exact>
97   *                             </jsdl:IndividualCPUCount>
98   *                             <jsdl:TotalResourceCount>
99   *                                 <jsdl:Exact>
100  *                                     $RESOURCES.getTotalResourceCount().getExactArray(0).
101  *                                     getDoubleValue()</jsdl:Exact>
102  *                             </jsdl:TotalResourceCount>
103  *                         </jsdl:Resources>
104  *                     </jsdl:JobDescription>
105  *                 </jsdl:JobDefinition>
106  *             </wsag:ServiceDescriptionTerm>
107  *             <wsag:ServiceDescriptionTerm wsag:Name="TIME_CONSTRAINT_SDT"
108  *                 wsag:ServiceName="RESERVATION_SERVICE">
109  *                 <wsag4jt:TimeConstraint
110  *                     xmlns:wsag4jt="http://schemas.wsag4j.org/2009/07/wsag4j-scheduling-extensions">
111  *                     <wsag4jt:StartTime>2010-05-20T00:00:00</wsag4jt:StartTime>
112  *                     <wsag4jt:Duration>1</wsag4jt:Duration>
113  *                 </wsag4jt:TimeConstraint>
114  *             </wsag:ServiceDescriptionTerm>
115  *         </wsag:All>
116  *     </wsag:Terms>
117  *     <wsag:CreationConstraints> ... </wsag:CreationConstraints>
118  * </wsag:AgreementTemplateType>
119  * }
120  * </pre> 
121  * 
122  * @author Oliver Waeldrich
123  * 
124  */
125 
126 //@formatter:on
127 public class AdvanceReservationComputeJobTemplate extends AbstractComputeJobTemplate
128 {
129 
130     /**
131      * Template name for which this pattern applies.
132      */
133     public static final String NAME = "ADVANCE-RESERVATION-COMPUTE-JOB";
134 
135     /**
136      * Template id for which this pattern applies.
137      */
138     public static final String ID = "1";
139 
140     private final AdvanceReservationPattern arTemplate;
141 
142     /**
143      * @param template
144      *            the agreement template XML representation
145      */
146     public AdvanceReservationComputeJobTemplate( AgreementTemplateType template )
147     {
148         super( template );
149 
150         //
151         // use the internal XML object for creating the pattern
152         //
153         template = getXMLObject();
154 
155         arTemplate = new AdvanceReservationPattern( template.getTerms().getAll() );
156     }
157 
158     /**
159      * @return the specified time constraints
160      * 
161      * @see AdvanceReservationPattern#getTimeConstraint()
162      */
163     public TimeConstraintType getTimeConstraint()
164     {
165         return arTemplate.getTimeConstraint();
166     }
167 
168     /**
169      * 
170      * @return an offer based on this template
171      * 
172      * @throws Exception
173      *             failed to create the offer object
174      */
175     public AdvanceReservationComputeJobOffer getOffer() throws Exception
176     {
177         return new AdvanceReservationComputeJobOffer( getXMLObject() );
178     }
179 }