[GitHub] brooklyn-server issue #927: Bundle type endpoint

2018-01-08 Thread tbouron
Github user tbouron commented on the issue:

https://github.com/apache/brooklyn-server/pull/927
  
I did but looks like I messed up my env somehow. Everything is fine now, 
sorry for the noise @ahgittin 


---


[GitHub] brooklyn-server issue #927: Bundle type endpoint

2018-01-08 Thread ahgittin
Github user ahgittin commented on the issue:

https://github.com/apache/brooklyn-server/pull/927
  
v strange.  are you sure it was built correctly @tbouron ?  it maybe had a 
`mvn clean install` pull down a slightly-old snapshot jar?  adding a new 
`*Resource` class needs updates in a few places but adding methods to the 
`*Api` classes is usually straightforward.


---


[GitHub] brooklyn-server issue #927: Bundle type endpoint

2018-01-08 Thread tbouron
Github user tbouron commented on the issue:

https://github.com/apache/brooklyn-server/pull/927
  
Actually @ahgittin, it seems the new endpoint is now available: I get a 404 
and it does not appear on the swagger page. Not sure what's going on here


---


[GitHub] brooklyn-server issue #928: Allow deprecation as the catalog item level

2018-01-08 Thread tbouron
Github user tbouron commented on the issue:

https://github.com/apache/brooklyn-server/pull/928
  
retest this please


---


[GitHub] brooklyn-server pull request #928: Allow deprecation as the catalog item lev...

2018-01-08 Thread tbouron
GitHub user tbouron opened a pull request:

https://github.com/apache/brooklyn-server/pull/928

Allow deprecation as the catalog item level

In YAML, one can mark a catalog item as `deprecated` but it works only when 
the flag it set as the `brooklyn.catalog` level.

This allows each catalog item to use the deprecated flag as one see fit. 
For example, I used it for the deprecated policies/enrichers we have within 
Brooklyn (see changes in bom files)

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/tbouron/brooklyn-server fix/catalog-deprecated

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/brooklyn-server/pull/928.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #928


commit 8d35ddb2b7a072213e8dfb01bcccf9d74accd55b
Author: Thomas Bouron 
Date:   2018-01-08T14:00:21Z

Allow deprecation as the catalog item level




---


[GitHub] brooklyn-server issue #909: Bump jclouds dependency from v2.0.2 to 2.0.3

2018-01-08 Thread geomacy
Github user geomacy commented on the issue:

https://github.com/apache/brooklyn-server/pull/909
  
@richardcloudsoft @andreaturli is there any reason why this shouldn't be 
merged now?


---


[jira] [Created] (BROOKLYN-572) Brooklyn CLI has problems on windows

2018-01-08 Thread Duncan Godwin (JIRA)
Duncan Godwin created BROOKLYN-572:
--

 Summary: Brooklyn CLI has problems on windows
 Key: BROOKLYN-572
 URL: https://issues.apache.org/jira/browse/BROOKLYN-572
 Project: Brooklyn
  Issue Type: Bug
Affects Versions: 1.0.0
Reporter: Duncan Godwin


* The CLI seems not to zip all artefacts correctly on windows
* Paths starting {{C://}} or another drive name have the error: {{Unrecognised 
protocol scheme: c}}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


Build failed in Jenkins: brooklyn-server-master-docker #31

2018-01-08 Thread Apache Jenkins Server
See 


Changes:

[alex.heneveld] rest tests for same types added

[alex.heneveld] adds bundle-specific type endpoint

--
[...truncated 7.01 MB...]
at org.testng.TestNG.run(TestNG.java:1104)
at 
org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:132)
at 
org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:193)
at 
org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:94)
at 
org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:147)
at 
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)

2018-01-08 12:33:35,435 WARN  Management Context 
LocalManagementContext[?-LmcKS1AT] running, creation stacktrace:
java.lang.Throwable: for construction stacktrace
at 
org.apache.brooklyn.core.mgmt.internal.LocalManagementContext.(LocalManagementContext.java:141)
at 
org.apache.brooklyn.core.mgmt.internal.LocalManagementContext.(LocalManagementContext.java:163)
at 
org.apache.brooklyn.core.mgmt.internal.LocalManagementContext.(LocalManagementContext.java:159)
at 
org.apache.brooklyn.core.test.entity.LocalManagementContextForTests.(LocalManagementContextForTests.java:45)
at 
org.apache.brooklyn.core.test.entity.LocalManagementContextForTests$Builder.build(LocalManagementContextForTests.java:185)
at 
org.apache.brooklyn.camp.brooklyn.AbstractYamlTest.newTestManagementContext(AbstractYamlTest.java:117)
at 
org.apache.brooklyn.camp.brooklyn.AbstractYamlTest$1.newMgmtContext(AbstractYamlTest.java:103)
at 
org.apache.brooklyn.camp.brooklyn.BrooklynCampPlatformLauncherAbstract.launch(BrooklynCampPlatformLauncherAbstract.java:48)
at 
org.apache.brooklyn.camp.brooklyn.AbstractYamlTest.setUpPlatform(AbstractYamlTest.java:106)
at 
org.apache.brooklyn.camp.brooklyn.AbstractYamlTest.setUp(AbstractYamlTest.java:95)
at sun.reflect.GeneratedMethodAccessor79.invoke(Unknown Source)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at 
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
at 
org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:590)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:851)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1177)
at 
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112)
at org.testng.TestRunner.privateRun(TestRunner.java:756)
at org.testng.TestRunner.run(TestRunner.java:610)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:387)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:382)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
at org.testng.TestNG.runSuites(TestNG.java:1133)
at org.testng.TestNG.run(TestNG.java:1104)
at 
org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:132)
at 
org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:193)
at 
org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:94)
at 
org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:147)
at 
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121)

2018-01-08 12:33:35,436 WARN  Management Context 
LocalManagementContext[?-u8bsChGd] running, creation stacktrace:
java.lang.Throwable: for construction stacktrace
at 
org.apache.brooklyn.core.mgmt.internal.LocalManagementContext.(LocalManagementContext.java:141)
at 

[GitHub] brooklyn-server pull request #927: Bundle type endpoint

2018-01-08 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/brooklyn-server/pull/927


---


[GitHub] brooklyn-server issue #927: Bundle type endpoint

2018-01-08 Thread tbouron
Github user tbouron commented on the issue:

https://github.com/apache/brooklyn-server/pull/927
  
Yep, the `latest` for bundles is not in the scope of this PR so I'm happy 
if there is another one for this.

Merging


---


[GitHub] brooklyn-server pull request #927: Bundle type endpoint

2018-01-08 Thread tbouron
Github user tbouron commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/927#discussion_r160129168
  
--- Diff: 
rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BundleAndTypeResourcesTest.java
 ---
@@ -1095,4 +1110,268 @@ private boolean checkTraits(boolean 
currentExpectedToBeWorking) {
 return currentExpectedToBeWorking;
 }
 
+@Test
+public void testAddSameTypeTwiceInSameBundle_SilentlyDeduped() throws 
Exception {
+final String symbolicName = 
"test.duplicate.type."+JavaClassNames.niceClassAndMethod();
+final String entityName = symbolicName+".type";
+
+File jar = createJar(ImmutableMap.of("catalog.bom", Joiner.on("\n").join(
+"brooklyn.catalog:",
+"  bundle: " + symbolicName,
+"  version: " + TEST_VERSION,
+"  items:",
+"  - id: " + entityName,
+"itemType: entity",
+"name: T",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity",
+"  - id: " + entityName,
+"itemType: entity",
+"name: T",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity")));
+
+Response result = client().path("/catalog/bundles")
+.header(HttpHeaders.CONTENT_TYPE, "application/x-jar")
+.post(Streams.readFully(new FileInputStream(jar)));
+HttpAsserts.assertHealthyStatusCode(result.getStatus());
+
+TypeSummary entity = client().path("/catalog/types/" + entityName 
+ "/" + TEST_VERSION)
+.get(TypeSummary.class);
+assertEquals(entity.getDisplayName(), "T");
+
+List entities = client().path("/catalog/types/" + 
entityName)
+.get(new GenericType() {});
+Asserts.assertSize(entities, 1);
+assertEquals(Iterables.getOnlyElement(entities), entity);
+
+BundleSummary bundle = client().path("/catalog/bundles/" + 
symbolicName + "/" + TEST_VERSION)
+.get(BundleSummary.class);
+Asserts.assertSize(bundle.getTypes(), 1);
+assertEquals(Iterables.getOnlyElement(bundle.getTypes()), entity);
+
+}
+
+@Test
+// different metadata is allowed as that doesn't affect operation (but 
different definition is not, see below)
+// if in same bundle, it's deduped and last one wins; should warn and 
could disallow, but if type is pulled in 
+// multiple times from copied files, it feels convenient just to 
dedupe and forgive minor metadata changes;
+// if in different bundles, see other test below, but in that case 
both are added
+public void 
testAddSameTypeTwiceInSameBundleDifferentDisplayName_LastOneWins() throws 
Exception {
+final String symbolicName = 
"test.duplicate.type."+JavaClassNames.niceClassAndMethod();
+final String entityName = symbolicName+".type";
+
+File jar = createJar(ImmutableMap.of("catalog.bom", Joiner.on("\n").join(
+"brooklyn.catalog:",
+"  bundle: " + symbolicName,
+"  version: " + TEST_VERSION,
+"  items:",
+"  - id: " + entityName,
+"itemType: entity",
+"name: T",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity",
+"  - id: " + entityName,
+"itemType: entity",
+"name: U",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity")));
+
+Response result = client().path("/catalog/bundles")
+.header(HttpHeaders.CONTENT_TYPE, "application/x-jar")
+.post(Streams.readFully(new FileInputStream(jar)));
+HttpAsserts.assertHealthyStatusCode(result.getStatus());
+
+TypeSummary entity = client().path("/catalog/types/" + entityName 
+ "/" + TEST_VERSION)
+.get(TypeSummary.class);
+assertEquals(entity.getDisplayName(), "U");
+
+List entities = client().path("/catalog/types/" + 
entityName)
+.get(new GenericType() {});
+Asserts.assertSize(entities, 1);
+assertEquals(Iterables.getOnlyElement(entities), entity);
+
+BundleSummary bundle = client().path("/catalog/bundles/" + 
symbolicName + "/" + TEST_VERSION)
+.get(BundleSummary.class);

[GitHub] brooklyn-server pull request #927: Bundle type endpoint

2018-01-08 Thread tbouron
Github user tbouron commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/927#discussion_r160128983
  
--- Diff: 
rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/BundleResource.java
 ---
@@ -107,6 +113,42 @@ protected ManagedBundle lookup(String symbolicName, 
String version) {
 }
 return b;
 }
+
+
+@Override
+public List getTypes(String symbolicName, String version) 
{
+ManagedBundle b = lookup(symbolicName, version);
+return TypeTransformer.bundleDetails(brooklyn(), b, 
ui.getBaseUriBuilder(), mgmt()).getTypes();
--- End diff --

Indeed, I did check that but forgot about it, ignore me then.


---


[GitHub] brooklyn-server pull request #926: [WIP] remove PortableTemplateBuilder

2018-01-08 Thread rdowner
Github user rdowner commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/926#discussion_r160125927
  
--- Diff: 
locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/pool/MachinePoolPredicates.java
 ---
@@ -82,40 +83,31 @@ public boolean apply(NodeMetadata input) {
  * (Caveat: If explicit Hardware, Image, and/or Template were 
specified in the template,
  * then the hash code probably will not detect it.)   
  **/
-public static boolean matches(ReusableMachineTemplate template, 
NodeMetadata m) {
+public static boolean matches(Template template, NodeMetadata m) {
 try {
 // tags and user metadata
 
-if (! m.getTags().containsAll( template.getTags(false) )) 
return false;
+if (! m.getTags().containsAll( 
template.getOptions().getTags())) return false;
 
-if (! isSubMapOf(template.getUserMetadata(false), 
m.getUserMetadata())) return false;
+if (! isSubMapOf(template.getOptions().getUserMetadata(), 
m.getUserMetadata())) return false;
 
 
 // common hardware parameters
+if (m.getHardware().getRam() < 
template.getHardware().getRam()) return false;
 
-if (template.getMinRam()!=null && m.getHardware().getRam() < 
template.getMinRam()) return false;
-
-if (template.getMinCores()!=null) {
+if (template.getHardware().getProcessors().get(0) != null) {
 double numCores = 0;
 for (Processor p: m.getHardware().getProcessors()) 
numCores += p.getCores();
-if (numCores+0.001 < template.getMinCores()) return false;
-}
-
-if (template.getIs64bit()!=null) {
-if (m.getOperatingSystem().is64Bit() != 
template.getIs64bit()) return false;
+if (numCores+0.001 < 
template.getHardware().getProcessors().get(0).getCores()) return false;
 }
 
-if (template.getOsFamily()!=null) {
+if (template.getImage().getOperatingSystem().getFamily() != 
null) {
 if (m.getOperatingSystem() == null || 
-
!template.getOsFamily().equals(m.getOperatingSystem().getFamily())) return 
false;
+
!template.getImage().getOperatingSystem().getFamily().equals(m.getOperatingSystem().getFamily()))
 return false;
 }
-if (template.getOsNameMatchesRegex()!=null) {
--- End diff --

This deleted line does not have an equivalent in the new version. Does this 
mean a potential a change in behaviour?


---


[GitHub] brooklyn-server pull request #926: [WIP] remove PortableTemplateBuilder

2018-01-08 Thread rdowner
Github user rdowner commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/926#discussion_r160127430
  
--- Diff: 
locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationStubbedTest.java
 ---
@@ -76,29 +76,12 @@ public FailObtainOnPurposeException(String message) {
 @BeforeMethod(alwaysRun=true)
 public void setUp() throws Exception {
 super.setUp();
-privateAddresses = ImmutableList.of("172.168.10.11");
-publicAddresses = ImmutableList.of("173.194.32.123");
-initNodeCreatorAndJcloudsLocation(newNodeCreator(), 
ImmutableMap.of());
+privateAddresses = ImmutableList.of(PRIVATE_IP_ADDRESS);
+publicAddresses = ImmutableList.of(PUBLIC_IP_ADDRESS);
+jcloudsLocation = initStubbedJcloudsLocation(ImmutableMap.of());
 }
 
-@Override
-protected NodeCreator newNodeCreator() {
-return new AbstractNodeCreator() {
-@Override protected NodeMetadata newNode(String group, 
Template template) {
-NodeMetadata result = new NodeMetadataBuilder()
-.id("myid")
-
.credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
-.loginPort(22)
-.status(Status.RUNNING)
-.publicAddresses(publicAddresses)
-.privateAddresses(privateAddresses)
-.build();
-return result;
-}
-};
-}
-
-@Test
+@Test(enabled = false)
--- End diff --

Is there a reason for disabling this test? If so, please add a comment.


---


[GitHub] brooklyn-server pull request #926: [WIP] remove PortableTemplateBuilder

2018-01-08 Thread rdowner
Github user rdowner commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/926#discussion_r160126361
  
--- Diff: 
locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
 ---
@@ -2609,7 +2609,7 @@ protected LoginCredentials waitForSshable(
 protected LoginCredentials waitForSshable(
 HostAndPort hostAndPort, Iterable 
credentialsToTry, ConfigBag setup) {
 String waitForSshable = setup.get(WAIT_FOR_SSHABLE);
-checkArgument(!"false".equalsIgnoreCase(waitForSshable), 
"waitForSshable called despite waitForSshable=%s for %s", waitForSshable, 
hostAndPort);
+//checkArgument(!"false".equalsIgnoreCase(waitForSshable), 
"waitForSshable called despite waitForSshable=%s for %s", waitForSshable, 
hostAndPort);
--- End diff --

Please avoid committing commented-out lines of code. Is this line supposed 
to be deleted, or was it commented out to help debugging?


---


[GitHub] brooklyn-server issue #927: Bundle type endpoint

2018-01-08 Thread ahgittin
Github user ahgittin commented on the issue:

https://github.com/apache/brooklyn-server/pull/927
  
+1 to supporting `latest` on bundle version -- i'll add that.  i think all 
other comments addressed.  `latest` bundle support could be new PR if you're 
happy to merge this now @tbouron .


---


[GitHub] brooklyn-server pull request #927: Bundle type endpoint

2018-01-08 Thread ahgittin
Github user ahgittin commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/927#discussion_r160127197
  
--- Diff: 
rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BundleAndTypeResourcesTest.java
 ---
@@ -1095,4 +1110,268 @@ private boolean checkTraits(boolean 
currentExpectedToBeWorking) {
 return currentExpectedToBeWorking;
 }
 
+@Test
+public void testAddSameTypeTwiceInSameBundle_SilentlyDeduped() throws 
Exception {
+final String symbolicName = 
"test.duplicate.type."+JavaClassNames.niceClassAndMethod();
+final String entityName = symbolicName+".type";
+
+File jar = createJar(ImmutableMap.of("catalog.bom", Joiner.on("\n").join(
+"brooklyn.catalog:",
+"  bundle: " + symbolicName,
+"  version: " + TEST_VERSION,
+"  items:",
+"  - id: " + entityName,
+"itemType: entity",
+"name: T",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity",
+"  - id: " + entityName,
+"itemType: entity",
+"name: T",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity")));
+
+Response result = client().path("/catalog/bundles")
+.header(HttpHeaders.CONTENT_TYPE, "application/x-jar")
+.post(Streams.readFully(new FileInputStream(jar)));
+HttpAsserts.assertHealthyStatusCode(result.getStatus());
+
+TypeSummary entity = client().path("/catalog/types/" + entityName 
+ "/" + TEST_VERSION)
+.get(TypeSummary.class);
+assertEquals(entity.getDisplayName(), "T");
+
+List entities = client().path("/catalog/types/" + 
entityName)
+.get(new GenericType() {});
+Asserts.assertSize(entities, 1);
+assertEquals(Iterables.getOnlyElement(entities), entity);
+
+BundleSummary bundle = client().path("/catalog/bundles/" + 
symbolicName + "/" + TEST_VERSION)
+.get(BundleSummary.class);
+Asserts.assertSize(bundle.getTypes(), 1);
+assertEquals(Iterables.getOnlyElement(bundle.getTypes()), entity);
+
+}
+
+@Test
+// different metadata is allowed as that doesn't affect operation (but 
different definition is not, see below)
+// if in same bundle, it's deduped and last one wins; should warn and 
could disallow, but if type is pulled in 
+// multiple times from copied files, it feels convenient just to 
dedupe and forgive minor metadata changes;
+// if in different bundles, see other test below, but in that case 
both are added
+public void 
testAddSameTypeTwiceInSameBundleDifferentDisplayName_LastOneWins() throws 
Exception {
+final String symbolicName = 
"test.duplicate.type."+JavaClassNames.niceClassAndMethod();
+final String entityName = symbolicName+".type";
+
+File jar = createJar(ImmutableMap.of("catalog.bom", Joiner.on("\n").join(
+"brooklyn.catalog:",
+"  bundle: " + symbolicName,
+"  version: " + TEST_VERSION,
+"  items:",
+"  - id: " + entityName,
+"itemType: entity",
+"name: T",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity",
+"  - id: " + entityName,
+"itemType: entity",
+"name: U",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity")));
+
+Response result = client().path("/catalog/bundles")
+.header(HttpHeaders.CONTENT_TYPE, "application/x-jar")
+.post(Streams.readFully(new FileInputStream(jar)));
+HttpAsserts.assertHealthyStatusCode(result.getStatus());
+
+TypeSummary entity = client().path("/catalog/types/" + entityName 
+ "/" + TEST_VERSION)
+.get(TypeSummary.class);
+assertEquals(entity.getDisplayName(), "U");
+
+List entities = client().path("/catalog/types/" + 
entityName)
+.get(new GenericType() {});
+Asserts.assertSize(entities, 1);
+assertEquals(Iterables.getOnlyElement(entities), entity);
+
+BundleSummary bundle = client().path("/catalog/bundles/" + 
symbolicName + "/" + TEST_VERSION)
+

[GitHub] brooklyn-server pull request #927: Bundle type endpoint

2018-01-08 Thread ahgittin
Github user ahgittin commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/927#discussion_r160126592
  
--- Diff: 
rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/BundleResource.java
 ---
@@ -107,6 +113,42 @@ protected ManagedBundle lookup(String symbolicName, 
String version) {
 }
 return b;
 }
+
+
+@Override
+public List getTypes(String symbolicName, String version) 
{
+ManagedBundle b = lookup(symbolicName, version);
+return TypeTransformer.bundleDetails(brooklyn(), b, 
ui.getBaseUriBuilder(), mgmt()).getTypes();
--- End diff --

`lookup` does the bundle entitlement check doesn't it?


---


[GitHub] brooklyn-server pull request #927: Bundle type endpoint

2018-01-08 Thread ahgittin
Github user ahgittin commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/927#discussion_r160126515
  
--- Diff: 
rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/BundleApi.java ---
@@ -88,6 +90,51 @@ public BundleSummary detail(
 @PathParam("version")
 String version);
 
+
+@Path("/{symbolicName}/{version}/types")
+@GET
+@ApiOperation(value = "Get all types declared in a given bundle", 
+response = TypeDetail.class)
+public List getTypes(
+@ApiParam(name = "symbolicName", value = "Bundle name to query", 
required = true)
+@PathParam("symbolicName")
+String symbolicName,
+@ApiParam(name = "version", value = "Version of bundle and of type 
to query", required = true)
+@PathParam("version")
+String version);
+
+@Path("/{symbolicName}/{version}/types/{typeSymbolicName}")
+@GET
+@ApiOperation(value = "Get detail on a given type in a given bundle", 
+response = TypeDetail.class)
+public TypeDetail getType(
+@ApiParam(name = "symbolicName", value = "Bundle name to query", 
required = true)
+@PathParam("symbolicName")
+String symbolicName,
+@ApiParam(name = "version", value = "Version of bundle and of type 
to query", required = true)
+@PathParam("version")
+String version,
+@ApiParam(name = "typeSymbolicName", value = "Type name to query", 
required = true)
+@PathParam("typeSymbolicName")
+String typeSymbolicName);
--- End diff --

it isn't `latest` - it is for case where type version = bundle version.  i 
think as that should be the normal case we should have an endpoint which 
doesn't require repeating version.


---


[GitHub] brooklyn-server pull request #927: Bundle type endpoint

2018-01-08 Thread tbouron
Github user tbouron commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/927#discussion_r160111321
  
--- Diff: 
rest/rest-api/src/main/java/org/apache/brooklyn/rest/api/BundleApi.java ---
@@ -88,6 +90,51 @@ public BundleSummary detail(
 @PathParam("version")
 String version);
 
+
+@Path("/{symbolicName}/{version}/types")
+@GET
+@ApiOperation(value = "Get all types declared in a given bundle", 
+response = TypeDetail.class)
+public List getTypes(
+@ApiParam(name = "symbolicName", value = "Bundle name to query", 
required = true)
+@PathParam("symbolicName")
+String symbolicName,
+@ApiParam(name = "version", value = "Version of bundle and of type 
to query", required = true)
+@PathParam("version")
+String version);
+
+@Path("/{symbolicName}/{version}/types/{typeSymbolicName}")
+@GET
+@ApiOperation(value = "Get detail on a given type in a given bundle", 
+response = TypeDetail.class)
+public TypeDetail getType(
+@ApiParam(name = "symbolicName", value = "Bundle name to query", 
required = true)
+@PathParam("symbolicName")
+String symbolicName,
+@ApiParam(name = "version", value = "Version of bundle and of type 
to query", required = true)
+@PathParam("version")
+String version,
+@ApiParam(name = "typeSymbolicName", value = "Type name to query", 
required = true)
+@PathParam("typeSymbolicName")
+String typeSymbolicName);
--- End diff --

I'm not sure to understand the difference between this endpoint and the one 
below (i.e. `/{symbolicName}/{version}/types/{typeSymbolicName}/{typeVersion}`).

It seems to that that it will be the same as 
`"/{symbolicName}/{version}/types/{typeSymbolicName}/latest` so probably not 
needed?


---


[GitHub] brooklyn-server pull request #927: Bundle type endpoint

2018-01-08 Thread tbouron
Github user tbouron commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/927#discussion_r160116429
  
--- Diff: 
rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BundleAndTypeResourcesTest.java
 ---
@@ -1095,4 +1110,268 @@ private boolean checkTraits(boolean 
currentExpectedToBeWorking) {
 return currentExpectedToBeWorking;
 }
 
+@Test
+public void testAddSameTypeTwiceInSameBundle_SilentlyDeduped() throws 
Exception {
+final String symbolicName = 
"test.duplicate.type."+JavaClassNames.niceClassAndMethod();
+final String entityName = symbolicName+".type";
+
+File jar = createJar(ImmutableMap.of("catalog.bom", Joiner.on("\n").join(
+"brooklyn.catalog:",
+"  bundle: " + symbolicName,
+"  version: " + TEST_VERSION,
+"  items:",
+"  - id: " + entityName,
+"itemType: entity",
+"name: T",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity",
+"  - id: " + entityName,
+"itemType: entity",
+"name: T",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity")));
+
+Response result = client().path("/catalog/bundles")
+.header(HttpHeaders.CONTENT_TYPE, "application/x-jar")
+.post(Streams.readFully(new FileInputStream(jar)));
+HttpAsserts.assertHealthyStatusCode(result.getStatus());
+
+TypeSummary entity = client().path("/catalog/types/" + entityName 
+ "/" + TEST_VERSION)
+.get(TypeSummary.class);
+assertEquals(entity.getDisplayName(), "T");
+
+List entities = client().path("/catalog/types/" + 
entityName)
+.get(new GenericType() {});
+Asserts.assertSize(entities, 1);
+assertEquals(Iterables.getOnlyElement(entities), entity);
+
+BundleSummary bundle = client().path("/catalog/bundles/" + 
symbolicName + "/" + TEST_VERSION)
+.get(BundleSummary.class);
+Asserts.assertSize(bundle.getTypes(), 1);
+assertEquals(Iterables.getOnlyElement(bundle.getTypes()), entity);
+
+}
+
+@Test
+// different metadata is allowed as that doesn't affect operation (but 
different definition is not, see below)
+// if in same bundle, it's deduped and last one wins; should warn and 
could disallow, but if type is pulled in 
+// multiple times from copied files, it feels convenient just to 
dedupe and forgive minor metadata changes;
+// if in different bundles, see other test below, but in that case 
both are added
+public void 
testAddSameTypeTwiceInSameBundleDifferentDisplayName_LastOneWins() throws 
Exception {
+final String symbolicName = 
"test.duplicate.type."+JavaClassNames.niceClassAndMethod();
+final String entityName = symbolicName+".type";
+
+File jar = createJar(ImmutableMap.of("catalog.bom", Joiner.on("\n").join(
+"brooklyn.catalog:",
+"  bundle: " + symbolicName,
+"  version: " + TEST_VERSION,
+"  items:",
+"  - id: " + entityName,
+"itemType: entity",
+"name: T",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity",
+"  - id: " + entityName,
+"itemType: entity",
+"name: U",
+"item:",
+"  type: 
org.apache.brooklyn.core.test.entity.TestEntity")));
+
+Response result = client().path("/catalog/bundles")
+.header(HttpHeaders.CONTENT_TYPE, "application/x-jar")
+.post(Streams.readFully(new FileInputStream(jar)));
+HttpAsserts.assertHealthyStatusCode(result.getStatus());
+
+TypeSummary entity = client().path("/catalog/types/" + entityName 
+ "/" + TEST_VERSION)
+.get(TypeSummary.class);
+assertEquals(entity.getDisplayName(), "U");
+
+List entities = client().path("/catalog/types/" + 
entityName)
+.get(new GenericType() {});
+Asserts.assertSize(entities, 1);
+assertEquals(Iterables.getOnlyElement(entities), entity);
+
+BundleSummary bundle = client().path("/catalog/bundles/" + 
symbolicName + "/" + TEST_VERSION)
+.get(BundleSummary.class);

[GitHub] brooklyn-server pull request #927: Bundle type endpoint

2018-01-08 Thread tbouron
Github user tbouron commented on a diff in the pull request:

https://github.com/apache/brooklyn-server/pull/927#discussion_r160111698
  
--- Diff: 
rest/rest-resources/src/main/java/org/apache/brooklyn/rest/resources/BundleResource.java
 ---
@@ -107,6 +113,42 @@ protected ManagedBundle lookup(String symbolicName, 
String version) {
 }
 return b;
 }
+
+
+@Override
+public List getTypes(String symbolicName, String version) 
{
+ManagedBundle b = lookup(symbolicName, version);
+return TypeTransformer.bundleDetails(brooklyn(), b, 
ui.getBaseUriBuilder(), mgmt()).getTypes();
--- End diff --

Don't we need an entitlement check on the bundle here?


---