Changeset 4131
- Timestamp:
- 2010-07-09 14:38:26 (3 years ago)
- Location:
- projects/lily/trunk
- Files:
-
- 3 added
- 9 edited
-
process/server/books_sample_indexerconf.xml (added)
-
process/server/books_sample_solr_schema.xml (added)
-
testfw/src/main/java/org/lilycms/testfw/HBaseProxy.java (modified) (1 diff)
-
testfw/src/main/java/org/lilycms/testfw/HBaseRunner.java (modified) (1 diff)
-
tools/import/README.txt (modified) (1 diff)
-
tools/import/books_sample.json (added)
-
tools/import/pom.xml (modified) (1 diff)
-
tools/import/src/main/java/org/lilycms/tools/import_/ImportTool.java (modified) (3 diffs)
-
tools/import/src/main/java/org/lilycms/tools/import_/JsonImportTool.java (modified) (7 diffs)
-
tools/tester/README.txt (modified) (1 diff)
-
tools/tester/config.json (modified) (1 diff)
-
tools/tester/pom.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
projects/lily/trunk/testfw/src/main/java/org/lilycms/testfw/HBaseProxy.java
r4111 r4131 73 73 case CONNECT: 74 74 CONF.set("hbase.zookeeper.quorum", "localhost"); 75 CONF.set("hbase.zookeeper.property.clientPort", "2181 2"); // matches HBaseRunner75 CONF.set("hbase.zookeeper.property.clientPort", "2181"); // matches HBaseRunner 76 76 addUserProps(CONF); 77 77 cleanTables(); -
projects/lily/trunk/testfw/src/main/java/org/lilycms/testfw/HBaseRunner.java
r4112 r4131 28 28 private File clusterTestBuildDir = null; 29 29 private Configuration conf; 30 private int zkPort = 2181 2;30 private int zkPort = 2181; 31 31 32 32 public static final String TEST_DIRECTORY_KEY = "test.build.data"; -
projects/lily/trunk/tools/import/README.txt
r4127 r4131 13 13 In a source setting, you can run this tool with maven: 14 14 15 mvn exec:java 15 mvn exec:java -Dexec.args="sample.json localhost:2181" -
projects/lily/trunk/tools/import/pom.xml
r4127 r4131 42 42 <mainClass>org.lilycms.tools.import_.JsonImportTool</mainClass> 43 43 <classpathScope>runtime</classpathScope> 44 <commandlineArgs>sample.json localhost:21812</commandlineArgs>45 44 </configuration> 46 45 </plugin> -
projects/lily/trunk/tools/import/src/main/java/org/lilycms/tools/import_/ImportTool.java
r4130 r4131 2 2 3 3 import org.lilycms.repository.api.*; 4 import org.lilycms.repoutil.VersionTag; 4 5 5 6 import java.util.*; … … 108 109 109 110 if (oldRecord != null) { 111 // Collect the set of vtag fields that should be automatically set to the last version. 112 // These are by contract those that have the value -1. 113 Set<QName> vtagFieldsToBeSetToLastVersion = new HashSet<QName>(); 114 for (Map.Entry<QName, Object> field : newRecord.getFields().entrySet()) { 115 if (field.getKey().getNamespace().equals(VersionTag.NAMESPACE) && field.getValue().equals(-1L)) { 116 vtagFieldsToBeSetToLastVersion.add(field.getKey()); 117 } 118 } 119 120 // Before comparing with the previous state, set the vtag fields to the currently last version 121 for (QName vtag : vtagFieldsToBeSetToLastVersion) { 122 newRecord.setField(vtag, oldRecord.getVersion()); 123 } 124 110 125 if (newRecord.softEquals(oldRecord)) { 111 126 importListener.existsAndEqual(EntityType.RECORD, null, newRecord.getId().toString()); … … 118 133 } 119 134 } 135 136 // Exclude vtag fields to-be-set-to-last-version from the update, will set those afterwards 137 for (QName vtag : vtagFieldsToBeSetToLastVersion) { 138 newRecord.delete(vtag, false); 139 } 140 141 // Update the record 120 142 Record updatedRecord = repository.update(newRecord); 143 144 // Now do a second update to set the vtags to version created 145 if (updatedRecord.getVersion() != null && !vtagFieldsToBeSetToLastVersion.isEmpty()) { 146 Record vtagsUpdate = repository.newRecord(newRecord.getId()); 147 for (QName vtag : vtagFieldsToBeSetToLastVersion) { 148 if (!(oldRecord.hasField(vtag) && oldRecord.getField(vtag).equals(updatedRecord.getVersion()))) { 149 vtagsUpdate.setField(vtag, updatedRecord.getVersion()); 150 } 151 } 152 153 if (!vtagsUpdate.getFields().isEmpty()) { 154 vtagsUpdate.setRecordType(updatedRecord.getRecordTypeId(), updatedRecord.getRecordTypeVersion()); 155 updatedRecord = repository.update(vtagsUpdate); 156 } 157 } 158 121 159 importListener.updated(EntityType.RECORD, null, updatedRecord.getId().toString(), updatedRecord.getVersion()); 122 160 return updatedRecord; 123 161 } 124 162 } else { 163 // For new records, let the vtag fields which should point to the last version point to 1 164 // TODO: this should check if there are actually any versioned fields. 165 for (Map.Entry<QName, Object> field : newRecord.getFields().entrySet()) { 166 if (field.getKey().getNamespace().equals(VersionTag.NAMESPACE) && field.getValue().equals(-1L)) { 167 newRecord.setField(field.getKey(), 1L); 168 } 169 } 125 170 Record createdRecord = repository.create(newRecord); 126 171 importListener.created(EntityType.RECORD, null, createdRecord.getId().toString()); -
projects/lily/trunk/tools/import/src/main/java/org/lilycms/tools/import_/JsonImportTool.java
r4130 r4131 10 10 import org.lilycms.client.Client; 11 11 import org.lilycms.repository.api.*; 12 import org.lilycms.repoutil.VersionTag; 13 12 14 import static org.lilycms.repoutil.JsonUtil.*; 13 15 … … 141 143 FieldType fieldType = typeManager.newFieldType(valueType, name, scope); 142 144 145 // Some sanity checks for version tag fields 146 if (fieldType.getName().getNamespace().equals(VersionTag.NAMESPACE)) { 147 if (fieldType.getScope() != Scope.NON_VERSIONED) 148 throw new ImportException("vtag fields should be in the non-versioned scope"); 149 150 if (!fieldType.getValueType().getPrimitive().getName().equals("LONG")) 151 throw new ImportException("vtag fields should be of type LONG"); 152 153 if (fieldType.getValueType().isMultiValue()) 154 throw new ImportException("vtag fields should not be multi-valued"); 155 156 if (fieldType.getValueType().isHierarchical()) 157 throw new ImportException("vtag fields should not be hierarchical"); 158 } 159 143 160 return importTool.importFieldType(fieldType); 144 161 } … … 183 200 if (name.contains(":")) { 184 201 QName qname = parseQName(name); 185 ValueType valueType = typeManager.getFieldTypeByName(qname).getValueType();186 Object value = readMultiValue(getNode(node, name), valueType, name);202 FieldType fieldType = typeManager.getFieldTypeByName(qname); 203 Object value = readMultiValue(getNode(node, name), fieldType, name); 187 204 record.setField(qname, value); 188 205 } … … 192 209 } 193 210 194 private Object readMultiValue(JsonNode node, ValueType valueType, String prop) throws ImportException {195 if ( valueType.isMultiValue()) {211 private Object readMultiValue(JsonNode node, FieldType fieldType, String prop) throws ImportException { 212 if (fieldType.getValueType().isMultiValue()) { 196 213 if (!node.isArray()) { 197 214 throw new ImportException("Multi-value value should be specified as array in " + prop); … … 200 217 List<Object> value = new ArrayList<Object>(); 201 218 for (int i = 0; i < node.size(); i++) { 202 value.add(readHierarchical(node.get(i), valueType, prop));219 value.add(readHierarchical(node.get(i), fieldType, prop)); 203 220 } 204 221 205 222 return value; 206 223 } else { 207 return readHierarchical(node, valueType, prop);208 } 209 } 210 211 private Object readHierarchical(JsonNode node, ValueType valueType, String prop) throws ImportException {212 if ( valueType.isHierarchical()) {224 return readHierarchical(node, fieldType, prop); 225 } 226 } 227 228 private Object readHierarchical(JsonNode node, FieldType fieldType, String prop) throws ImportException { 229 if (fieldType.getValueType().isHierarchical()) { 213 230 if (!node.isArray()) { 214 231 throw new ImportException("Hierarchical value should be specified as an array in " + prop); … … 217 234 Object[] elements = new Object[node.size()]; 218 235 for (int i = 0; i < node.size(); i++) { 219 elements[i] = readPrimitive(node.get(i), valueType, prop);236 elements[i] = readPrimitive(node.get(i), fieldType, prop); 220 237 } 221 238 222 239 return new HierarchyPath(elements); 223 240 } else { 224 return readPrimitive(node, valueType, prop);225 } 226 } 227 228 private Object readPrimitive(JsonNode node, ValueType valueType, String prop) throws ImportException {229 String primitive = valueType.getPrimitive().getName();241 return readPrimitive(node, fieldType, prop); 242 } 243 } 244 245 private Object readPrimitive(JsonNode node, FieldType fieldType, String prop) throws ImportException { 246 String primitive = fieldType.getValueType().getPrimitive().getName(); 230 247 231 248 if (primitive.equals("STRING")) { … … 240 257 return node.getIntValue(); 241 258 } else if (primitive.equals("LONG")) { 259 // Special handling for version tag fields 260 if (fieldType.getName().getNamespace().equals(VersionTag.NAMESPACE)) { 261 if (node.isTextual()) { 262 if (node.getTextValue().equals("last")) { 263 return -1L; 264 } else { 265 throw new ImportException("Version tag fields can only have 'last' as string value. Field " + 266 prop + ", value " + node.getTextValue()); 267 } 268 } else if (node.isIntegralNumber()) { 269 if (node.getLongValue() < 0) { 270 throw new ImportException("Version tag fields should be larger than 0. Field " + prop + 271 ", value " + node.getLongValue()); 272 } 273 } else { 274 throw new ImportException("Expected long value or \"last\" for " + prop); 275 } 276 } 277 242 278 if (!node.isIntegralNumber()) 243 279 throw new ImportException("Expected long value for " + prop); -
projects/lily/trunk/tools/tester/README.txt
r4125 r4131 17 17 In a source setting, you can run this tool with maven: 18 18 19 mvn exec:java 19 mvn exec:java -Dexec.args="config.json" -
projects/lily/trunk/tools/tester/config.json
r4125 r4131 1 1 { 2 "zookeeper": "localhost:2181 2",2 "zookeeper": "localhost:2181", 3 3 4 4 "reportFile": "testreport.csv", -
projects/lily/trunk/tools/tester/pom.xml
r4125 r4131 42 42 <mainClass>org.lilycms.tools.tester.Tester</mainClass> 43 43 <classpathScope>runtime</classpathScope> 44 <commandlineArgs>config.json</commandlineArgs>45 44 </configuration> 46 45 </plugin>
Note: See TracChangeset
for help on using the changeset viewer.