mirror of https://github.com/apache/jclouds.git
Merge pull request #1372 from digitalsanctum/issue-1357
relaxed vApp description parsing
This commit is contained in:
commit
d1e9b78010
|
@ -47,9 +47,7 @@ import org.jclouds.vcloud.domain.VApp;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Splitter;
|
import com.google.common.base.Splitter;
|
||||||
|
|
||||||
/**
|
/** @author Adrian Cole */
|
||||||
* @author Adrian Cole
|
|
||||||
*/
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
|
public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
|
||||||
@Resource
|
@Resource
|
||||||
|
@ -77,9 +75,16 @@ public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
|
||||||
builder.ids(from.getHref().toASCIIString());
|
builder.ids(from.getHref().toASCIIString());
|
||||||
builder.uri(from.getHref());
|
builder.uri(from.getHref());
|
||||||
builder.name(from.getName());
|
builder.name(from.getName());
|
||||||
if (!isNullOrEmpty(from.getDescription()) && from.getDescription().indexOf('=') != -1)
|
if (!isNullOrEmpty(from.getDescription())
|
||||||
|
&& from.getDescription().indexOf('=') != -1
|
||||||
|
&& from.getDescription().indexOf('\n') != -1) {
|
||||||
|
try {
|
||||||
addMetadataAndParseTagsFromCommaDelimitedValue(builder,
|
addMetadataAndParseTagsFromCommaDelimitedValue(builder,
|
||||||
Splitter.on('\n').withKeyValueSeparator("=").split(from.getDescription()));
|
Splitter.on('\n').withKeyValueSeparator("=").split(from.getDescription()));
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
}
|
||||||
builder.hostname(from.getName());
|
builder.hostname(from.getName());
|
||||||
builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
|
builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
|
||||||
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
|
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.jclouds.vcloud.compute.functions;
|
package org.jclouds.vcloud.compute.functions;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -116,6 +117,7 @@ public class VAppToNodeMetadataTest {
|
||||||
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||||
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
||||||
NodeMetadata node = converter.apply(result);
|
NodeMetadata node = converter.apply(result);
|
||||||
|
assertNotNull(node);
|
||||||
assertEquals(node.getUserMetadata(), ImmutableMap.<String, String>of());
|
assertEquals(node.getUserMetadata(), ImmutableMap.<String, String>of());
|
||||||
assertEquals(node.getTags(), ImmutableSet.<String>of());
|
assertEquals(node.getTags(), ImmutableSet.<String>of());
|
||||||
assertEquals(node.getLocation(), location);
|
assertEquals(node.getLocation(), location);
|
||||||
|
@ -123,6 +125,51 @@ public class VAppToNodeMetadataTest {
|
||||||
assertEquals(node.getPublicAddresses(), ImmutableSet.of());
|
assertEquals(node.getPublicAddresses(), ImmutableSet.of());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testWithMetadataParseException() {
|
||||||
|
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
|
||||||
|
.scope(LocationScope.PROVIDER).build();
|
||||||
|
Injector injector = createInjectorWithLocation(location);
|
||||||
|
InputStream is = getClass().getResourceAsStream("/vapp-pool.xml");
|
||||||
|
Factory factory = injector.getInstance(ParseSax.Factory.class);
|
||||||
|
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||||
|
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
||||||
|
ImmutableMap<String, String> metadata = ImmutableMap.<String, String>of();
|
||||||
|
ImmutableSet<String> tags = ImmutableSet.<String>of();
|
||||||
|
|
||||||
|
String description = " user=user_ssoid_1\nuid=3b7bb605-bb30-4e62-a3de-9076b052dee7 label='foo-DEVELOPMENT' date=2013-01-22 17:39:28.252";
|
||||||
|
|
||||||
|
result = new VAppImpl(result.getName(), result.getType(), result.getHref(), result.getStatus(), result.getVDC(),
|
||||||
|
description, result.getTasks(), result.isOvfDescriptorUploaded(), result.getChildren(),
|
||||||
|
result.getNetworkSection());
|
||||||
|
|
||||||
|
NodeMetadata node = converter.apply(result);
|
||||||
|
assertNotNull(node);
|
||||||
|
assertEquals(node.getUserMetadata(), metadata);
|
||||||
|
assertEquals(node.getTags(), tags);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWithMetadataNoNewLines() {
|
||||||
|
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
|
||||||
|
.scope(LocationScope.PROVIDER).build();
|
||||||
|
Injector injector = createInjectorWithLocation(location);
|
||||||
|
InputStream is = getClass().getResourceAsStream("/vapp-pool.xml");
|
||||||
|
Factory factory = injector.getInstance(ParseSax.Factory.class);
|
||||||
|
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||||
|
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
||||||
|
ImmutableMap<String, String> metadata = ImmutableMap.<String, String>of();
|
||||||
|
ImmutableSet<String> tags = ImmutableSet.<String>of();
|
||||||
|
|
||||||
|
String description = " user=user_ssoid_1 uid=3b7bb605-bb30-4e62-a3de-9076b052dee7 label='foo-DEVELOPMENT' date=2013-01-22 17:39:28.252";
|
||||||
|
|
||||||
|
result = new VAppImpl(result.getName(), result.getType(), result.getHref(), result.getStatus(), result.getVDC(),
|
||||||
|
description, result.getTasks(), result.isOvfDescriptorUploaded(), result.getChildren(),
|
||||||
|
result.getNetworkSection());
|
||||||
|
|
||||||
|
NodeMetadata node = converter.apply(result);
|
||||||
|
assertNotNull(node);
|
||||||
|
assertEquals(node.getUserMetadata(), metadata);
|
||||||
|
assertEquals(node.getTags(), tags);
|
||||||
|
}
|
||||||
|
|
||||||
public void testWithEncodedMetadata() {
|
public void testWithEncodedMetadata() {
|
||||||
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
|
Location location = new LocationBuilder().id("https://1.1.1.1/api/v1.0/vdc/1").description("description")
|
||||||
|
@ -146,6 +193,7 @@ public class VAppToNodeMetadataTest {
|
||||||
result.getNetworkSection());
|
result.getNetworkSection());
|
||||||
|
|
||||||
NodeMetadata node = converter.apply(result);
|
NodeMetadata node = converter.apply(result);
|
||||||
|
assertNotNull(node);
|
||||||
assertEquals(node.getUserMetadata(), metadata);
|
assertEquals(node.getUserMetadata(), metadata);
|
||||||
assertEquals(node.getTags(), tags);
|
assertEquals(node.getTags(), tags);
|
||||||
|
|
||||||
|
@ -160,6 +208,7 @@ public class VAppToNodeMetadataTest {
|
||||||
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||||
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
||||||
NodeMetadata node = converter.apply(result);
|
NodeMetadata node = converter.apply(result);
|
||||||
|
assertNotNull(node);
|
||||||
assertEquals(node.getLocation(), location);
|
assertEquals(node.getLocation(), location);
|
||||||
assertEquals(node.getPrivateAddresses(), ImmutableSet.of());
|
assertEquals(node.getPrivateAddresses(), ImmutableSet.of());
|
||||||
assertEquals(node.getPublicAddresses(), ImmutableSet.of());
|
assertEquals(node.getPublicAddresses(), ImmutableSet.of());
|
||||||
|
@ -175,6 +224,7 @@ public class VAppToNodeMetadataTest {
|
||||||
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
|
||||||
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
VAppToNodeMetadata converter = injector.getInstance(VAppToNodeMetadata.class);
|
||||||
NodeMetadata node = converter.apply(result);
|
NodeMetadata node = converter.apply(result);
|
||||||
|
assertNotNull(node);
|
||||||
assertEquals(node.getLocation(), location);
|
assertEquals(node.getLocation(), location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue