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.pattern; 36 37 import org.apache.xmlbeans.XmlObject; 38 import org.ggf.schemas.jsdl.x2005.x11.jsdl.JobDefinitionType; 39 import org.ggf.schemas.jsdl.x2005.x11.jsdl.ResourcesType; 40 import org.ogf.schemas.graap.wsAgreement.TermCompositorType; 41 42 /** 43 * ComputeResourcePattern 44 * 45 * The term compositor contains a RESOURCE_SDT with a JSDL document describing a resource. 46 * 47 * <pre> 48 * {@code 49 * <wsag:Template wsag:TemplateId="1" 50 * xmlns:wsag="http://schemas.ggf.org/graap/2007/03/ws-agreement"> 51 * <wsag:Name>ComputeApplicationTemplate</wsag:Name> 52 * <wsag:Context> 53 * <wsag:ServiceProvider>AgreementResponder</wsag:ServiceProvider> 54 * <wsag:TemplateId>1</wsag:TemplateId> 55 * <wsag:TemplateName>ComputeApplicationTemplate</wsag:TemplateName> 56 * </wsag:Context> 57 * <wsag:Terms> 58 * <wsag:All> 59 * <wsag:ServiceDescriptionTerm wsag:Name="SDT_1" 60 * wsag:ServiceName="SERVICE_1"> 61 * Put your service description terms here ... 62 * </wsag:ServiceDescriptionTerm> 63 * ... 64 * <wsag:ServiceDescriptionTerm wsag:Name="RESOURCE_SDT" 65 * wsag:ServiceName="COMPUTE_SERVICE"> 66 * <jsdl:JobDefinition xmlns:jsdl="http://schemas.ggf.org/jsdl/2005/11/jsdl"> 67 * <jsdl:JobDescription> 68 * <jsdl:Resources> 69 * <jsdl:IndividualCPUTime> 70 * <jsdl:Exact>3600.0</jsdl:Exact> 71 * </jsdl:IndividualCPUTime> 72 * <jsdl:IndividualCPUCount> 73 * <jsdl:Exact>2.0</jsdl:Exact> 74 * </jsdl:IndividualCPUCount> 75 * <jsdl:TotalResourceCount> 76 * <jsdl:Exact>1.0</jsdl:Exact> 77 * </jsdl:TotalResourceCount> 78 * </jsdl:Resources> 79 * </jsdl:JobDescription> 80 * </jsdl:JobDefinition> 81 * </wsag:ServiceDescriptionTerm> 82 * 83 * </wsag:All> 84 * </wsag:Terms> 85 * <wsag:CreationConstraints /> 86 * </wsag:Template> 87 * } 88 * </pre> 89 * 90 * @author Oliver Waeldrich 91 * 92 */ 93 public class ComputeResourcePattern extends AbstractPattern 94 { 95 96 private JobDefinitionType resourceSDT; 97 98 private final String resourceXPath = "declare namespace jsdl='http://schemas.ggf.org/jsdl/2005/11/jsdl';" 99 + "declare namespace wsag='http://schemas.ggf.org/graap/2007/03/ws-agreement';" 100 + "$this/wsag:ServiceDescriptionTerm[@wsag:Name = 'RESOURCE_SDT']/jsdl:JobDefinition"; 101 102 /** 103 * Initiates the pattern on a given term compositor. 104 * 105 * @param termCompositor 106 * the term compositor 107 */ 108 public ComputeResourcePattern( TermCompositorType termCompositor ) 109 { 110 super( termCompositor ); 111 initialize(); 112 } 113 114 /** 115 * initializes the pattern object after creation 116 */ 117 protected void initialize() 118 { 119 // 120 // find the exactly one element, that contains the application SDTs 121 // 122 XmlObject[] resourceSelection = getTermCompositor().selectPath( getResourceXPath() ); 123 124 if ( resourceSelection.length != 1 ) 125 { 126 throw new IllegalStateException( "Invalid number of resource SDTs in quote." ); 127 } 128 129 resourceSDT = (JobDefinitionType) resourceSelection[0]; 130 131 } 132 133 /** 134 * 135 * @return the JSDL resource section in the SDT 136 */ 137 public ResourcesType getResourceDefinition() 138 { 139 return resourceSDT.getJobDescription().getResources(); 140 } 141 142 /** 143 * Sub classes overwrite this method in order to provide a custom XPath expression for resource SDT 144 * selection. 145 * 146 * @return the resourceXPath 147 */ 148 public String getResourceXPath() 149 { 150 return resourceXPath; 151 } 152 153 }