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.samples.site; 36 37 import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionDocument; 38 import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType; 39 import org.ogf.graap.wsag.api.Agreement; 40 import org.ogf.graap.wsag.api.AgreementOffer; 41 import org.ogf.graap.wsag.api.exceptions.AgreementFactoryException; 42 import org.ogf.graap.wsag.server.actions.AbstractCreateAgreementAction; 43 import org.ogf.graap.wsag.server.actions.ActionInitializationException; 44 import org.ogf.schemas.graap.wsAgreement.ServiceDescriptionTermType; 45 46 /** 47 * This action is used as example in the WSAG4J documentation. 48 * 49 * @author Oliver Waeldrich 50 * 51 */ 52 // START SNIPPET: SampleCreateAgreement 53 public class ExampleCreateAgreementAction extends AbstractCreateAgreementAction 54 { 55 56 /** 57 * The createAgreement() method is invoked when an offer was received that is based on the template 58 * associated with this action. Since the structure of the template (and therefore the structure of the 59 * offer) is known, we can simply access and the process offer content. 60 * 61 * The structure and the content of the offer can be restricted by defining Creation Constraints in the 62 * agreement template. 63 * 64 * {@inheritDoc} 65 */ 66 public Agreement createAgreement( AgreementOffer offer ) throws AgreementFactoryException 67 { 68 69 // 70 // This action is configured for a template that contains one 71 // service description term that describes a computational service. 72 // First we get the service description term. 73 // 74 ServiceDescriptionTermType sdt = offer.getTerms().getAll().getServiceDescriptionTermArray( 0 ); 75 76 // 77 // Now select the service description from the service description term. 78 // This particular service description term contains a JSDL job definition document 79 // of the type JobDefinitionType. We select the document and cast it to the 80 // appropriate type. 81 // 82 JobDefinitionType job = 83 (JobDefinitionType) sdt.selectChildren( JobDefinitionDocument.type.getDocumentElementName() )[0]; 84 85 // 86 // Now we can access the properties of the job ... 87 // 88 job.getJobDescription().getResources().getTotalResourceCount(); 89 job.getJobDescription().getResources().getIndividualCPUCount(); 90 job.getJobDescription().getResources().getTotalPhysicalMemory(); 91 92 // 93 // ... and instantiate a service. 94 // 95 ExampleService service = new ExampleService( job ); 96 service.start(); 97 98 // 99 // Finally we create a new agreement instance based on the received offer. 100 // The agreement properties are automatically initialized based on the offer. 101 // For each service description term (guarantee term) a corresponding service 102 // term state (guarantee term state is initialized.) 103 // 104 ExampleAgreement agreement = new ExampleAgreement( offer ); 105 agreement.setService( service ); 106 107 return agreement; 108 } 109 110 /** 111 * This method is invoked when the action is initialized. The initialization process takes place when the 112 * WSAG4J server is started. 113 * 114 * {@inheritDoc} 115 */ 116 public void initialize() throws ActionInitializationException 117 { 118 // 119 // add implementation specific code here 120 // 121 } 122 } 123 // END SNIPPET: SampleCreateAgreement