001/* Module initializer for hadoop module. 002 * 003 * Copyright (c) 2012-2013 The Regents of the University of California. 004 * All rights reserved. 005 * 006 * '$Author: crawl $' 007 * '$Date: 2014-11-12 23:21:09 +0000 (Wed, 12 Nov 2014) $' 008 * '$Revision: 33070 $' 009 * 010 * Permission is hereby granted, without written agreement and without 011 * license or royalty fees, to use, copy, modify, and distribute this 012 * software and its documentation for any purpose, provided that the above 013 * copyright notice and the following two paragraphs appear in all copies 014 * of this software. 015 * 016 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 017 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 018 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 019 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 020 * SUCH DAMAGE. 021 * 022 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 023 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 024 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 025 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 026 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 027 * ENHANCEMENTS, OR MODIFICATIONS. 028 * 029 */ 030 031package org.kepler.hadoop.util; 032 033import java.util.HashMap; 034import java.util.Map; 035 036import org.kepler.ddp.actor.pattern.SingleInputPatternActor; 037import org.kepler.ddp.actor.pattern.Types; 038 039import ptolemy.data.type.Type; 040 041////////////////////////////////////////////////////////////////////////// 042////DDPPatternActorUtil 043 044/** 045* This class includes a datatype used in HadoopDirector. 046* Its elements: 1) name; 2) workflow xml string; 3) data types of the inputs and outputs; 4) implementation class. 047* 048* @author Jianwu Wang (jianwu@sdsc.edu) 049* @version $Id: DDPPatternActorUtil.java 33070 2014-11-12 23:21:09Z crawl $ 050*/ 051 052public class DDPPatternActorUtil { 053 054 public DDPPatternActorUtil(SingleInputPatternActor actor, String name, String actorString, 055 java.util.Map<String, Type> typeMap) { 056 this.actor = actor; 057 this.name = name; 058 this.xml = actorString; 059 this.typeMap = typeMap; 060 } 061 public DDPPatternActorUtil(SingleInputPatternActor actor, String name, String impClass, String inputKeyValueType, String outputKeyValueType) throws ClassNotFoundException { 062 this.actor = actor; 063 this.name = name; 064 this.impClass = impClass; 065 this.typeMap = new HashMap<String, Type>(); 066 setKeyValueTypes("in", inputKeyValueType); 067 setKeyValueTypes("out", outputKeyValueType); 068 } 069 070 public SingleInputPatternActor getActor() { 071 return actor; 072 } 073 public void setActor(SingleInputPatternActor actor) { 074 this.actor = actor; 075 } 076 077 public String getName() { 078 return name; 079 } 080 public void setName(String name) { 081 this.name = name; 082 } 083 public String getXml() { 084 return xml; 085 } 086 public void setXml(String xml) { 087 this.xml = xml; 088 } 089 public Map<String, Type> getTypeMap() { 090 return typeMap; 091 } 092 public void setTypeMap(Map<String, Type> typeMap) { 093 this.typeMap = typeMap; 094 } 095 096 public String getImpClassName() { 097 return impClass; 098 } 099 public void setImpClassName(String impClass) { 100 this.impClass = impClass; 101 } 102 103 public void setKeyValueTypes(String preFix, String typesStr){ 104 105 final String typesCleanedStr = typesStr.replaceAll(",", "").trim(); 106 final String[] typesArray = typesCleanedStr.split("\\s+"); 107 final Type keyType = Types.getTypeFromString(typesArray[0]); 108 typeMap.put(preFix+"Key", keyType); 109 final Type valueType = Types.getTypeFromString(typesArray[1]); 110 typeMap.put(preFix+"Value", valueType); 111 } 112 113 /** actor. */ 114 private SingleInputPatternActor actor; 115 116 /** actor name. */ 117 private String name; 118 119 /** The xml content of the sub-workflow in the DDP actor. */ 120 private String xml; 121 122 /** The string for implementation class. */ 123 private String impClass = null; 124 125 /** The type map (name, type) of input/output ports of the DDP actor. */ 126 private Map<String, Type> typeMap; 127 128}