http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/ApplicationComponentTemplateRestResource.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/ApplicationComponentTemplateRestResource.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/ApplicationComponentTemplateRestResource.java deleted file mode 100644 index 32c626e..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/ApplicationComponentTemplateRestResource.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.resource; - -import io.swagger.annotations.Api; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import org.apache.brooklyn.camp.server.dto.ApplicationComponentTemplateDto; - -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; - -@Path(ApplicationComponentTemplateRestResource.URI_PATH) -@Api("Application Component Template resources") -@Produces("application/json") -public class ApplicationComponentTemplateRestResource extends AbstractCampRestResource { - - public static final String URI_PATH = PlatformRestResource.CAMP_URI_PATH + "/application-component-templates"; - - @Path("/{id}") - @ApiOperation(value = "Get a specific application component template", - response = ApplicationComponentTemplateDto.class) - @GET - public ApplicationComponentTemplateDto get( - @ApiParam(value = "ID of item being retrieved", required = true) - @PathParam("id") String id) { - return dto().adapt(lookup(camp().applicationComponentTemplates(), id)); - } - -}
http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/AssemblyRestResource.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/AssemblyRestResource.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/AssemblyRestResource.java deleted file mode 100644 index 892cdb5..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/AssemblyRestResource.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.resource; - -import io.swagger.annotations.Api; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import org.apache.brooklyn.camp.server.dto.AssemblyDto; - -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; - -@Path(AssemblyRestResource.URI_PATH) -@Api("Assembly resources") -@Produces("application/json") -public class AssemblyRestResource extends AbstractCampRestResource { - -// private static final Logger log = LoggerFactory.getLogger(AssemblyRestResource.class); - - public static final String URI_PATH = PlatformRestResource.CAMP_URI_PATH + "/assemblies"; - - @Path("/{id}") - @ApiOperation(value = "Get a specific assembly", - response = AssemblyDto.class) - @GET - public AssemblyDto get( - @ApiParam(value = "ID of item being retrieved", required = true) - @PathParam("id") String id) { - return dto().adapt(lookup(camp().assemblies(), id)); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/AssemblyTemplateRestResource.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/AssemblyTemplateRestResource.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/AssemblyTemplateRestResource.java deleted file mode 100644 index c3ccae6..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/AssemblyTemplateRestResource.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.resource; - -import io.swagger.annotations.Api; -import java.net.URI; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.brooklyn.camp.server.dto.AssemblyTemplateDto; -import org.apache.brooklyn.camp.spi.Assembly; -import org.apache.brooklyn.camp.spi.AssemblyTemplate; -import org.apache.brooklyn.util.exceptions.Exceptions; - -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; - -@Path(AssemblyTemplateRestResource.URI_PATH) -@Api("Assembly Template resources") -@Produces("application/json") -public class AssemblyTemplateRestResource extends AbstractCampRestResource { - - private static final Logger log = LoggerFactory.getLogger(AssemblyTemplateRestResource.class); - - public static final String URI_PATH = PlatformRestResource.CAMP_URI_PATH + "/assembly-templates"; - - @Path("/{id}") - @ApiOperation(value = "Get a specific assembly template", - response = AssemblyTemplateDto.class) - @GET - public AssemblyTemplateDto get( - @ApiParam(value = "ID of item being retrieved", required = true) - @PathParam("id") String id) { - return dto().adapt(lookup(camp().assemblyTemplates(), id)); - } - - @Path("/{id}") - @ApiOperation(value = "Instantiate a specific assembly template" - // TODO AssemblyDto, or location thereto? -// , responseClass = AssemblyTemplateDto.CLASS_NAME - ) - @POST - public Response post( - @Context UriInfo info, - @ApiParam(value = "ID of item being retrieved", required = true) - @PathParam("id") String id) { - try { - log.info("CAMP REST instantiating AT "+id); - AssemblyTemplate at = lookup(camp().assemblyTemplates(), id); - Assembly assembly = at.getInstantiator().newInstance().instantiate(at, camp()); - // see http://stackoverflow.com/questions/13702481/javax-response-prepends-method-path-when-setting-location-header-path-on-status - // for why we have to return absolute path - URI assemblyUri = info.getBaseUriBuilder().path( dto().adapt(assembly).getUri() ).build(); - return Response.created(assemblyUri).build(); - } catch (Exception e) { - log.error("Unable to create AT "+id+": "+e); - throw Exceptions.propagate(e); - } - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformComponentRestResource.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformComponentRestResource.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformComponentRestResource.java deleted file mode 100644 index 77d20dc..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformComponentRestResource.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.resource; - -import io.swagger.annotations.Api; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import org.apache.brooklyn.camp.server.dto.PlatformComponentDto; - -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; - -@Path(PlatformComponentRestResource.URI_PATH) -@Api("Platform Component resources") -@Produces("application/json") -public class PlatformComponentRestResource extends AbstractCampRestResource { - - public static final String URI_PATH = PlatformRestResource.CAMP_URI_PATH + "/platform-components"; - - @Path("/{id}") - @ApiOperation(value = "Get a specific platform component", - response = PlatformComponentDto.class) - @GET - public PlatformComponentDto get( - @ApiParam(value = "ID of item being retrieved", required = true) - @PathParam("id") String id) { - return dto().adapt(lookup(camp().platformComponents(), id)); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformComponentTemplateRestResource.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformComponentTemplateRestResource.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformComponentTemplateRestResource.java deleted file mode 100644 index b334757..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformComponentTemplateRestResource.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.resource; - -import io.swagger.annotations.Api; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; - -import org.apache.brooklyn.camp.server.dto.PlatformComponentTemplateDto; - -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; - -@Path(PlatformComponentTemplateRestResource.URI_PATH) -@Api("Platform Component Template resources") -@Produces("application/json") -public class PlatformComponentTemplateRestResource extends AbstractCampRestResource { - - public static final String URI_PATH = PlatformRestResource.CAMP_URI_PATH + "/platform-component-templates"; - - @Path("/{id}") - @ApiOperation(value = "Get a specific platform component template", - response = PlatformComponentTemplateDto.class) - @GET - public PlatformComponentTemplateDto get( - @ApiParam(value = "ID of item being retrieved", required = true) - @PathParam("id") String id) { - return dto().adapt(lookup(camp().platformComponentTemplates(), id)); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformRestResource.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformRestResource.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformRestResource.java deleted file mode 100644 index 9d98877..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/resource/PlatformRestResource.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.resource; - -import io.swagger.annotations.Api; -import java.io.InputStream; -import java.io.StringReader; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.apache.brooklyn.camp.server.dto.PlatformDto; -import org.apache.brooklyn.camp.server.rest.util.WebResourceUtils; -import org.apache.brooklyn.camp.spi.AssemblyTemplate; - -import io.swagger.annotations.ApiOperation; - -//import io.brooklyn.camp.rest.apidoc.Apidoc; - -@Path(PlatformRestResource.CAMP_URI_PATH) -@Api("Platform (root)") -@Produces("application/json") -public class PlatformRestResource extends AbstractCampRestResource { - - private static final Logger log = LoggerFactory.getLogger(PlatformRestResource.class); - - public static final String CAMP_URI_PATH = "/camp/v11"; - - @ApiOperation(value = "Return the Platform (root) resource", - response = PlatformDto.class) - @GET - public PlatformDto get() { - return dto().adapt(camp().root()); - } - - @POST - @Consumes({MediaType.APPLICATION_JSON}) - public Response postJson(@Context UriInfo info, String json) { - return postYaml(info, json); - } - - @POST - @Consumes({"application/x-yaml"}) - public Response postYaml(@Context UriInfo info, String yaml) { - log.debug("YAML pdp:\n"+yaml); - AssemblyTemplate template = camp().pdp().registerDeploymentPlan(new StringReader(yaml)); - return created(info, template); - } - - @POST - @Consumes({"application/x-tar", "application/x-tgz", "application/x-zip"}) - public Response postArchive(@Context UriInfo info, InputStream archiveInput) { - log.debug("ARCHIVE pdp"); - AssemblyTemplate template = camp().pdp().registerPdpFromArchive(archiveInput); - return created(info, template); - } - - protected Response created(UriInfo info, AssemblyTemplate template) { - return WebResourceUtils.created(info, dto().adapt(template).getUri()); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampJsons.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampJsons.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampJsons.java deleted file mode 100644 index cd61b0c..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampJsons.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.util; - -import org.apache.brooklyn.util.exceptions.Exceptions; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; - -public class CampJsons { - - public static String prettyJson(Object o) { - try { - ObjectMapper mapper = new ObjectMapper(); - mapper.enable(SerializationFeature.INDENT_OUTPUT); - return mapper.writeValueAsString(o); - } catch (JsonProcessingException e) { - throw Exceptions.propagate(e); - } - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampRestContext.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampRestContext.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampRestContext.java deleted file mode 100644 index 66d6cf8..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampRestContext.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.util; - -import javax.servlet.ServletContext; - -import org.apache.brooklyn.camp.CampPlatform; -import org.apache.brooklyn.camp.server.rest.CampServer; - -import com.google.common.base.Preconditions; - -public class CampRestContext { - - private final ServletContext servletContext; - private CampPlatform platform; - private DtoFactory dto; - - public CampRestContext(ServletContext servletContext) { - this.servletContext = servletContext; - } - - public synchronized CampPlatform camp() { - if (platform!=null) return platform; - platform = (CampPlatform) servletContext.getAttribute(CampServer.CAMP_PLATFORM_ATTRIBUTE); - return Preconditions.checkNotNull(platform, "CAMP platform instance not available from ServletContext"); - } - - public DtoFactory dto() { - if (dto!=null) return dto; - dto = (DtoFactory) servletContext.getAttribute(CampServer.DTO_FACTORY); - return Preconditions.checkNotNull(dto, "CAMP DTO factory instance not available from ServletContext"); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampRestGuavas.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampRestGuavas.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampRestGuavas.java deleted file mode 100644 index 22758a4..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/CampRestGuavas.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.util; - -import org.apache.brooklyn.camp.spi.AbstractResource; - -import com.google.common.base.Function; - -public class CampRestGuavas { - - public static final Function<AbstractResource,String> IDENTITY_OF_REST_RESOURCE = - new Function<AbstractResource,String>() { - public String apply(AbstractResource input) { return input.getId(); } - }; - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/DtoFactory.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/DtoFactory.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/DtoFactory.java deleted file mode 100644 index c745053..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/DtoFactory.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.util; - -import java.util.Map; - -import javax.ws.rs.Path; - -import org.apache.brooklyn.camp.CampPlatform; -import org.apache.brooklyn.camp.server.dto.ApplicationComponentDto; -import org.apache.brooklyn.camp.server.dto.ApplicationComponentTemplateDto; -import org.apache.brooklyn.camp.server.dto.AssemblyDto; -import org.apache.brooklyn.camp.server.dto.AssemblyTemplateDto; -import org.apache.brooklyn.camp.server.dto.PlatformComponentDto; -import org.apache.brooklyn.camp.server.dto.PlatformComponentTemplateDto; -import org.apache.brooklyn.camp.server.dto.PlatformDto; -import org.apache.brooklyn.camp.server.rest.resource.AbstractCampRestResource; -import org.apache.brooklyn.camp.server.rest.resource.ApplicationComponentRestResource; -import org.apache.brooklyn.camp.server.rest.resource.ApplicationComponentTemplateRestResource; -import org.apache.brooklyn.camp.server.rest.resource.AssemblyRestResource; -import org.apache.brooklyn.camp.server.rest.resource.AssemblyTemplateRestResource; -import org.apache.brooklyn.camp.server.rest.resource.PlatformComponentRestResource; -import org.apache.brooklyn.camp.server.rest.resource.PlatformComponentTemplateRestResource; -import org.apache.brooklyn.camp.server.rest.resource.PlatformRestResource; -import org.apache.brooklyn.camp.spi.AbstractResource; -import org.apache.brooklyn.camp.spi.ApplicationComponent; -import org.apache.brooklyn.camp.spi.ApplicationComponentTemplate; -import org.apache.brooklyn.camp.spi.Assembly; -import org.apache.brooklyn.camp.spi.AssemblyTemplate; -import org.apache.brooklyn.camp.spi.PlatformComponent; -import org.apache.brooklyn.camp.spi.PlatformComponentTemplate; -import org.apache.brooklyn.camp.spi.PlatformRootSummary; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.net.Urls; - -import com.google.common.base.Function; -import com.google.common.base.Preconditions; - -public class DtoFactory { - - private CampPlatform platform; - private String uriBase; - - private UriFactory uriFactory; - - public DtoFactory(CampPlatform campPlatform, String uriBase) { - this.platform = campPlatform; - this.uriBase = uriBase; - - uriFactory = new UriFactory(); - uriFactory.registerIdentifiableRestResource(PlatformRootSummary.class, PlatformRestResource.class); - uriFactory.registerIdentifiableRestResource(AssemblyTemplate.class, AssemblyTemplateRestResource.class); - uriFactory.registerIdentifiableRestResource(PlatformComponentTemplate.class, PlatformComponentTemplateRestResource.class); - uriFactory.registerIdentifiableRestResource(ApplicationComponentTemplate.class, ApplicationComponentTemplateRestResource.class); - uriFactory.registerIdentifiableRestResource(Assembly.class, AssemblyRestResource.class); - uriFactory.registerIdentifiableRestResource(PlatformComponent.class, PlatformComponentRestResource.class); - uriFactory.registerIdentifiableRestResource(ApplicationComponent.class, ApplicationComponentRestResource.class); - } - - public CampPlatform getPlatform() { - return platform; - } - - public UriFactory getUriFactory() { - return uriFactory; - } - - public String uri(AbstractResource x) { - return getUriFactory().uri(x); - } - - public String uri(Class<? extends AbstractResource> targetType, String id) { - return getUriFactory().uri(targetType, id); - } - - public AssemblyTemplateDto adapt(AssemblyTemplate assemblyTemplate) { - return AssemblyTemplateDto.newInstance(this, assemblyTemplate); - } - public PlatformComponentTemplateDto adapt(PlatformComponentTemplate platformComponentTemplate) { - return PlatformComponentTemplateDto.newInstance(this, platformComponentTemplate); - } - public ApplicationComponentTemplateDto adapt(ApplicationComponentTemplate applicationComponentTemplate) { - return ApplicationComponentTemplateDto.newInstance(this, applicationComponentTemplate); - } - - public AssemblyDto adapt(Assembly assembly) { - return AssemblyDto.newInstance(this, assembly); - } - public PlatformComponentDto adapt(PlatformComponent platformComponent) { - return PlatformComponentDto.newInstance(this, platformComponent); - } - public ApplicationComponentDto adapt(ApplicationComponent applicationComponent) { - return ApplicationComponentDto.newInstance(this, applicationComponent); - } - - public PlatformDto adapt(PlatformRootSummary root) { - return PlatformDto.newInstance(this, root); - } - - public class UriFactory { - /** registry of generating a URI given an object */ - Map<Class<?>,Function<Object,String>> registryResource = new MutableMap<Class<?>, Function<Object,String>>(); - /** registry of generating a URI given an ID */ - Map<Class<?>,Function<String,String>> registryId = new MutableMap<Class<?>, Function<String,String>>(); - - /** registers a function which generates a URI given a type; note that this method cannot be used for links */ - @SuppressWarnings("unchecked") - public synchronized <T> void registerResourceUriFunction(Class<T> type, Function<T,String> fnUri) { - registryResource.put(type, (Function<Object, String>) fnUri); - } - - /** registers a type to generate a URI which concatenates the given base with the - * result of the given function to generate an ID against an object of the given type */ - public synchronized <T> void registerIdentityFunction(Class<T> type, final String resourceTypeUriBase, final Function<T,String> fnIdentity) { - final Function<String,String> fnUriFromId = new Function<String,String>() { - public String apply(String id) { - return Urls.mergePaths(resourceTypeUriBase, id); - } - }; - registryId.put(type, (Function<String, String>) fnUriFromId); - registerResourceUriFunction(type, new Function<T,String>() { - public String apply(T input) { - return fnUriFromId.apply(fnIdentity.apply(input)); - } - }); - } - - /** registers a CAMP Resource type against a RestResource, generating the URI - * by concatenating the @Path annotation on the RestResource with the ID of the CAMP resource */ - @SuppressWarnings({ "unchecked", "rawtypes" }) - public synchronized <T extends AbstractResource> void registerIdentifiableRestResource(Class<T> type, Class<? extends AbstractCampRestResource> restResource) { - registerIdentityFunction(type, - uriOfRestResource(restResource), - (Function) CampRestGuavas.IDENTITY_OF_REST_RESOURCE); - } - - public String uri(Class<? extends AbstractResource> targetType, String id) { - return Preconditions.checkNotNull(registryId.get(targetType), - "No REST ID converter registered for %s (id %s)", targetType, id) - .apply(id); - } - - public String uri(AbstractResource x) { - return Preconditions.checkNotNull(registryResource.get(x.getClass()), - "No REST converter registered for %s (%s)", x.getClass(), x) - .apply(x); - } - - public String uriOfRestResource(Class<?> restResourceClass) { - return Urls.mergePaths(uriBase, - Preconditions.checkNotNull(restResourceClass.getAnnotation(Path.class), - "No @Path on type %s", restResourceClass) - .value()); - } - - - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/WebResourceUtils.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/WebResourceUtils.java b/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/WebResourceUtils.java deleted file mode 100644 index 964ae34..0000000 --- a/brooklyn-server/camp/camp-server/src/main/java/org/apache/brooklyn/camp/server/rest/util/WebResourceUtils.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.util; - -import java.net.URI; - -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriInfo; - -import org.apache.brooklyn.camp.server.dto.ApiErrorDto; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class WebResourceUtils { - - private static final Logger log = LoggerFactory.getLogger(WebResourceUtils.class); - - public static WebApplicationException notFound(String format, Object... args) { - String msg = String.format(format, args); - if (log.isDebugEnabled()) log.debug("returning 404 notFound("+msg+")"); - throw new WebApplicationException(Response.status(Response.Status.NOT_FOUND) - .type(MediaType.APPLICATION_JSON_TYPE) - .entity(ApiErrorDto.builder().message(msg).build()).build()); - } - - public static WebApplicationException preconditionFailed(String format, Object... args) { - String msg = String.format(format, args); - if (log.isDebugEnabled()) log.debug("returning 412 preconditionFailed("+msg+")"); - throw new WebApplicationException(Response.status(Response.Status.PRECONDITION_FAILED) - .type(MediaType.APPLICATION_JSON_TYPE) - .entity(ApiErrorDto.builder().message(msg).build()).build()); - } - - public static Response created(UriInfo info, String resourceUriPath) { - // see http://stackoverflow.com/questions/13702481/javax-response-prepends-method-path-when-setting-location-header-path-on-status - // for why we have to return absolute path - URI resourceUri = info.getBaseUriBuilder().path( resourceUriPath ).build(); - return Response.created(resourceUri).build(); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/ApplicationCompomentTemplateDtoTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/ApplicationCompomentTemplateDtoTest.java b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/ApplicationCompomentTemplateDtoTest.java deleted file mode 100644 index 476f23e..0000000 --- a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/ApplicationCompomentTemplateDtoTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.dto; - -import org.apache.brooklyn.camp.CampPlatform; -import org.apache.brooklyn.camp.server.dto.ApplicationComponentTemplateDto; -import org.apache.brooklyn.camp.server.rest.util.DtoFactory; -import org.apache.brooklyn.camp.spi.ApplicationComponentTemplate; -import org.apache.brooklyn.camp.test.mock.web.MockWebPlatform; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -public class ApplicationCompomentTemplateDtoTest { - - private static final Logger log = LoggerFactory.getLogger(ApplicationCompomentTemplateDtoTest.class); - - @Test - public void testAppServerPct() { - CampPlatform p = MockWebPlatform.newPlatform(); - DtoFactory f = new DtoFactory(p, ""); - - ApplicationComponentTemplate t = MockWebPlatform.WAR; - ApplicationComponentTemplateDto dto = f.adapt(t); - - log.info("War PCT serialized as: "+BasicDtoTest.tree(dto)); - Assert.assertEquals(dto.getName(), t.getName()); - Assert.assertNotNull(dto.getCreatedAsString()); - Assert.assertTrue(dto.getCreatedAsString().startsWith("20")); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/BasicDtoTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/BasicDtoTest.java b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/BasicDtoTest.java deleted file mode 100644 index 6c5cabf..0000000 --- a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/BasicDtoTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.dto; - -import java.io.IOException; - -import org.apache.brooklyn.camp.server.dto.DtoCustomAttributes; -import org.apache.brooklyn.util.collections.MutableMap; -import org.apache.brooklyn.util.exceptions.Exceptions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -/** Tests identity methods and custom attributes for DTO, including Jackson JSON serialization */ -public class BasicDtoTest { - - private static final Logger log = LoggerFactory.getLogger(BasicDtoTest.class); - - @Test - public void testSimple() throws IOException { - DtoCustomAttributes l = new DtoCustomAttributes(null); - - JsonNode t = tree(l); - Assert.assertEquals(t.size(), 0); - Assert.assertTrue(l.getCustomAttributes()==null || l.getCustomAttributes().isEmpty()); - - Assert.assertEquals(l, new ObjectMapper().readValue(t.toString(), DtoCustomAttributes.class)); - } - - @Test - public void testCustomAttrs() throws IOException { - DtoCustomAttributes l = new DtoCustomAttributes(MutableMap.of("bar", "bee")); - - JsonNode t = tree(l); - Assert.assertEquals(t.size(), 1); - Assert.assertEquals(t.get("bar").asText(), l.getCustomAttributes().get("bar")); - - Assert.assertEquals(l, new ObjectMapper().readValue(t.toString(), DtoCustomAttributes.class)); - } - - @Test - public void testIdentity() throws IOException { - DtoCustomAttributes l1 = new DtoCustomAttributes(null); - DtoCustomAttributes l2 = new DtoCustomAttributes(MutableMap.of("bar", "bee")); - DtoCustomAttributes l2o = new DtoCustomAttributes(MutableMap.of("bar", "bee")); - - Assert.assertEquals(l1, l1); - Assert.assertEquals(l2, l2); - Assert.assertEquals(l2, l2o); - Assert.assertNotEquals(l1, l2); - - Assert.assertEquals(l1.hashCode(), l1.hashCode()); - Assert.assertEquals(l2.hashCode(), l2.hashCode()); - Assert.assertEquals(l2.hashCode(), l2o.hashCode()); - Assert.assertNotEquals(l1.hashCode(), l2.hashCode()); - } - - public static JsonNode tree(Object l) { - try { - ObjectMapper m = new ObjectMapper(); - String s = m.writeValueAsString(l); - log.info(l.toString()+" -> "+s); - JsonNode t = m.readTree(s); - return t; - } catch (Exception e) { - throw Exceptions.propagate(e); - } - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/LinkDtoTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/LinkDtoTest.java b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/LinkDtoTest.java deleted file mode 100644 index e326faa..0000000 --- a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/LinkDtoTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.dto; - -import java.io.IOException; - -import org.apache.brooklyn.camp.server.dto.LinkDto; -import org.apache.brooklyn.util.collections.MutableMap; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -@Test -public class LinkDtoTest { - -// private static final Logger log = LoggerFactory.getLogger(LinkDtoTest.class); - - @Test - public void testSimple() throws IOException { - LinkDto l = LinkDto.newInstance("http://foo", "Foo"); - - JsonNode t = BasicDtoTest.tree(l); - Assert.assertEquals(t.size(), 2); - Assert.assertEquals(t.get("href").asText(), l.getHref()); - Assert.assertEquals(t.get("targetName").asText(), l.getTargetName()); - Assert.assertTrue(l.getCustomAttributes()==null || l.getCustomAttributes().isEmpty()); - - Assert.assertEquals(l, new ObjectMapper().readValue(t.toString(), LinkDto.class)); - } - - @Test - public void testCustomAttrs() throws IOException { - LinkDto l = LinkDto.newInstance("http://foo", "Foo", MutableMap.of("bar", "bee")); - - JsonNode t = BasicDtoTest.tree(l); - Assert.assertEquals(t.size(), 3); - Assert.assertEquals(t.get("href").asText(), l.getHref()); - Assert.assertEquals(t.get("targetName").asText(), l.getTargetName()); - Assert.assertEquals(t.get("bar").asText(), l.getCustomAttributes().get("bar")); - - Assert.assertEquals(l, new ObjectMapper().readValue(t.toString(), LinkDto.class)); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/PlatformCompomentTemplateDtoTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/PlatformCompomentTemplateDtoTest.java b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/PlatformCompomentTemplateDtoTest.java deleted file mode 100644 index eb9f552..0000000 --- a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/PlatformCompomentTemplateDtoTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.dto; - -import org.apache.brooklyn.camp.CampPlatform; -import org.apache.brooklyn.camp.server.dto.PlatformComponentTemplateDto; -import org.apache.brooklyn.camp.server.rest.util.DtoFactory; -import org.apache.brooklyn.camp.spi.PlatformComponentTemplate; -import org.apache.brooklyn.camp.test.mock.web.MockWebPlatform; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -public class PlatformCompomentTemplateDtoTest { - - private static final Logger log = LoggerFactory.getLogger(PlatformCompomentTemplateDtoTest.class); - - @Test - public void testAppServerPct() { - CampPlatform p = MockWebPlatform.newPlatform(); - DtoFactory f = new DtoFactory(p, ""); - - PlatformComponentTemplate t = MockWebPlatform.APPSERVER; - PlatformComponentTemplateDto dto = f.adapt(t); - - log.info("Web PCT serialized as: "+BasicDtoTest.tree(dto)); - Assert.assertEquals(dto.getName(), t.getName()); - Assert.assertNotNull(dto.getCreatedAsString()); - Assert.assertTrue(dto.getCreatedAsString().startsWith("20")); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/ResourceDtoTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/ResourceDtoTest.java b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/ResourceDtoTest.java deleted file mode 100644 index dd7a01c..0000000 --- a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/dto/ResourceDtoTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.dto; - -import java.io.IOException; -import java.util.Arrays; - -import org.apache.brooklyn.camp.BasicCampPlatform; -import org.apache.brooklyn.camp.commontypes.RepresentationSkew; -import org.apache.brooklyn.camp.server.dto.ResourceDto; -import org.apache.brooklyn.camp.server.rest.CampServer; -import org.apache.brooklyn.camp.server.rest.util.CampRestGuavas; -import org.apache.brooklyn.camp.spi.AbstractResource; -import org.testng.Assert; -import org.testng.annotations.Test; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -@Test -public class ResourceDtoTest { - -// private static final Logger log = LoggerFactory.getLogger(ResourceDtoTest.class); - - CampServer s; - AbstractResource rr; - ResourceDto r; - - @SuppressWarnings("unchecked") - protected void initSimpleDto() { - s = new CampServer(new BasicCampPlatform(), "http://atest/"); - s.getDtoFactory().getUriFactory().registerIdentityFunction(AbstractResource.class, "basic", CampRestGuavas.IDENTITY_OF_REST_RESOURCE); - rr = AbstractResource.builder().name("Name").description("a description"). - tags(Arrays.asList("tag1", "tag 2")).representationSkew(RepresentationSkew.NONE).build(); - r = ResourceDto.newInstance(s.getDtoFactory(), rr); - } - - @Test - public void testSimpleCreation() throws IOException { - initSimpleDto(); - - Assert.assertNotNull(r.getCreatedAsString()); - Assert.assertEquals(r.getName(), "Name"); - Assert.assertEquals(r.getDescription(), "a description"); - Assert.assertEquals(r.getTags(), Arrays.asList("tag1", "tag 2")); - Assert.assertEquals(r.getRepresentationSkew(), RepresentationSkew.NONE); - } - - public void testSimpleSerializationAndDeserialization() throws IOException { - initSimpleDto(); - - JsonNode t = BasicDtoTest.tree(r); - -// Assert.assertEquals(t.get("uri").asText(), r.getUri()); - ResourceDto r2 = new ObjectMapper().readValue(t.toString(), ResourceDto.class); - Assert.assertNotNull(r2.getCreated()); - Assert.assertEquals(r, r2); - } - - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/rest/resource/PlatformRestResourceTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/rest/resource/PlatformRestResourceTest.java b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/rest/resource/PlatformRestResourceTest.java deleted file mode 100644 index f0d2138..0000000 --- a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/rest/resource/PlatformRestResourceTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.rest.resource; - -import org.apache.brooklyn.camp.server.dto.PlatformComponentTemplateDto; -import org.apache.brooklyn.camp.server.dto.PlatformDto; -import org.apache.brooklyn.camp.server.rest.resource.PlatformRestResource; -import org.apache.brooklyn.camp.server.rest.resource.PlatformRestResourceTest; -import org.apache.brooklyn.camp.server.test.fixture.AbstractRestResourceTest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.Assert; -import org.testng.annotations.Test; - -public class PlatformRestResourceTest extends AbstractRestResourceTest { - - private static final Logger log = LoggerFactory.getLogger(PlatformRestResourceTest.class); - - @Test - public void testPlatformIncludesList() { - PlatformDto p = load(PlatformRestResource.CAMP_URI_PATH, PlatformDto.class); - PlatformComponentTemplateDto pct = load(p.getPlatformComponentTemplates().get(0).getHref(), PlatformComponentTemplateDto.class); - log.debug("Loaded PCT via REST: "+pct); - Assert.assertNotNull(pct.getName()); - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/test/fixture/AbstractRestResourceTest.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/test/fixture/AbstractRestResourceTest.java b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/test/fixture/AbstractRestResourceTest.java deleted file mode 100644 index f283f5c..0000000 --- a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/test/fixture/AbstractRestResourceTest.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.test.fixture; - -import java.net.URL; - -import org.apache.brooklyn.camp.BasicCampPlatform; -import org.apache.brooklyn.camp.server.rest.CampServer; -import org.apache.brooklyn.camp.test.mock.web.MockWebPlatform; -import org.apache.brooklyn.util.exceptions.Exceptions; -import org.apache.brooklyn.util.net.Urls; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.reporters.Files; - -import com.fasterxml.jackson.databind.ObjectMapper; - -public class AbstractRestResourceTest { - - private static final Logger log = LoggerFactory.getLogger(AbstractRestResourceTest.class); - - protected BasicCampPlatform platform; - protected CampServer server; - - @BeforeClass - public void startServer() { - platform = new BasicCampPlatform(); - populate(); - - // new server - server = new CampServer(platform, "").start(); - } - - protected void populate() { - MockWebPlatform.populate(platform); - } - - @AfterClass - public void stopServer() { - if (server!=null) - server.stop(); - } - - public String load(String path) { - try { - String base = "http://localhost:"+server.getPort(); - String x = path.startsWith(base) ? path : Urls.mergePaths(base, path); - log.debug("Reading from: "+x); - String s = Files.streamToString(new URL(x).openStream()); - log.debug("Result from "+x+": "+s); - return s; - } catch (Exception e) { - throw Exceptions.propagate(e); - } - } - - public <T> T load(String path, Class<T> type) { - try { - String data = load(path); - return new ObjectMapper().readValue(data, type); - } catch (Exception e) { - throw Exceptions.propagate(e); - } - } - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/test/fixture/InMemoryCamp.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/test/fixture/InMemoryCamp.java b/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/test/fixture/InMemoryCamp.java deleted file mode 100644 index 114324d..0000000 --- a/brooklyn-server/camp/camp-server/src/test/java/org/apache/brooklyn/camp/server/test/fixture/InMemoryCamp.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.camp.server.test.fixture; - -import org.apache.brooklyn.camp.BasicCampPlatform; -import org.apache.brooklyn.camp.server.rest.CampServer; -import org.apache.brooklyn.camp.test.mock.web.MockWebPlatform; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class InMemoryCamp { - - private static final Logger log = LoggerFactory.getLogger(InMemoryCamp.class); - - - public static void main(String[] args) { - - // new platform with some mock types and some data structures - - // interface CampComponent - // getComponentTemplate() -> operations, links, etc - - // platformView.getComponent(id) -> returns instance of domain-specific component type - BasicCampPlatform p = new BasicCampPlatform(); - MockWebPlatform.populate(p); - - // new server - CampServer s = new CampServer(p, "").start(); - - log.info("Running at: "+s.getUriBase()); - // requests against server - - } - - -} http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/camp/pom.xml ---------------------------------------------------------------------- diff --git a/brooklyn-server/camp/pom.xml b/brooklyn-server/camp/pom.xml deleted file mode 100644 index 579c473..0000000 --- a/brooklyn-server/camp/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <packaging>pom</packaging> - - <groupId>org.apache.brooklyn.camp</groupId> - <artifactId>camp-parent</artifactId> - - <name>CAMP Server Parent Project</name> - <description> - Parent/Root Project for Oasis CAMP Server modules - </description> - - <parent> - <groupId>org.apache.brooklyn</groupId> - <artifactId>brooklyn-parent</artifactId> - <version>0.9.0-SNAPSHOT</version> <!-- BROOKLYN_VERSION --> - <relativePath>../parent/pom.xml</relativePath> - </parent> - - <modules> - <module>camp-base</module> - <module>camp-server</module> - <module>camp-brooklyn</module> - </modules> - -</project> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/pom.xml ---------------------------------------------------------------------- diff --git a/brooklyn-server/core/pom.xml b/brooklyn-server/core/pom.xml deleted file mode 100644 index 3be573d..0000000 --- a/brooklyn-server/core/pom.xml +++ /dev/null @@ -1,321 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. ---> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <packaging>jar</packaging> - - <artifactId>brooklyn-core</artifactId> - - <name>Brooklyn Core</name> - <description> - Entity implementation classes, events, and other core elements - </description> - - <parent> - <groupId>org.apache.brooklyn</groupId> - <artifactId>brooklyn-parent</artifactId> - <version>0.9.0-SNAPSHOT</version> <!-- BROOKLYN_VERSION --> - <relativePath>../parent/pom.xml</relativePath> - </parent> - - <dependencies> - <dependency> - <groupId>org.apache.brooklyn</groupId> - <artifactId>brooklyn-test-support</artifactId> - <version>${project.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.brooklyn</groupId> - <artifactId>brooklyn-rt-felix</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.brooklyn</groupId> - <artifactId>brooklyn-api</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.brooklyn</groupId> - <artifactId>brooklyn-utils-groovy</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>net.schmizz</groupId> - <artifactId>sshj</artifactId> - </dependency> - <dependency> - <groupId>com.thoughtworks.xstream</groupId> - <artifactId>xstream</artifactId> - </dependency> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-mapper-asl</artifactId> - </dependency> - <dependency> - <groupId>com.google.code.gson</groupId> - <artifactId>gson</artifactId> - </dependency> - - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - </dependency> - - <dependency> - <groupId>org.bouncycastle</groupId> - <artifactId>bcprov-ext-jdk15on</artifactId> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.bouncycastle</groupId> - <artifactId>bcpkix-jdk15on</artifactId> - <scope>compile</scope> - <exclusions> - <!-- provided by bcprov-ext instead --> - <exclusion> - <groupId>org.bouncycastle</groupId> - <artifactId>bcprov-jdk15on</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>org.reflections</groupId> - <artifactId>reflections</artifactId> - <exclusions> - <exclusion> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </exclusion> - <exclusion> - <groupId>xml-apis</groupId> - <artifactId>xml-apis</artifactId> - </exclusion> - </exclusions> - </dependency> - - <dependency> - <groupId>org.freemarker</groupId> - <artifactId>freemarker</artifactId> - </dependency> - - <dependency> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy-all</artifactId> - </dependency> - <dependency> - <groupId>org.apache.brooklyn</groupId> - <artifactId>brooklyn-utils-common</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpcore</artifactId> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> - <dependency> - <groupId>org.codehaus.jackson</groupId> - <artifactId>jackson-core-asl</artifactId> - </dependency> - <dependency> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </dependency> - <dependency> - <groupId>com.google.code.findbugs</groupId> - <artifactId>jsr305</artifactId> - </dependency> - <dependency> - <groupId>com.maxmind.geoip2</groupId> - <artifactId>geoip2</artifactId> - </dependency> - <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - </dependency> - - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>mx4j</groupId> - <artifactId>mx4j-tools</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.google.mockwebserver</groupId> - <artifactId>mockwebserver</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-webapp</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-security</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.jayway.jsonpath</groupId> - <artifactId>json-path</artifactId> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-server</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.eclipse.jetty</groupId> - <artifactId>jetty-util</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>com.beust</groupId> - <artifactId>jcommander</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - <classifier>tests</classifier> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.brooklyn</groupId> - <artifactId>brooklyn-rt-osgi</artifactId> - <version>${project.version}</version> - <classifier>tests</classifier> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.brooklyn</groupId> - <artifactId>brooklyn-utils-common</artifactId> - <version>${project.version}</version> - <classifier>tests</classifier> - <scope>test</scope> - </dependency> - </dependencies> - - <build> - <plugins> - <plugin> - <artifactId>maven-compiler-plugin</artifactId> - <inherited>true</inherited> - <configuration> - <fork>true</fork> - <verbose>false</verbose> - </configuration> - <executions> - <!-- - Compile only Groovy files with the eclipse-groovy compiler. - Java files compiled by default-testCompile execution inherited from parent. - --> - <execution> - <id>groovy-testCompile</id> - <phase>test-compile</phase> - <goals> - <goal>testCompile</goal> - </goals> - <configuration> - <compilerId>groovy-eclipse-compiler</compilerId> - <includes> - <include>**/*.groovy</include> - </includes> - <fork>true</fork> - <verbose>false</verbose> - <source>${java.version}</source> - <target>${java.version}</target> - </configuration> - </execution> - </executions> - <dependencies> - <dependency> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy-eclipse-compiler</artifactId> - <version>2.9.1-01</version> - </dependency> - <dependency> - <groupId>org.codehaus.groovy</groupId> - <artifactId>groovy-eclipse-batch</artifactId> - <version>2.4.3-01</version> - </dependency> - </dependencies> - </plugin> - <plugin> - <groupId>org.apache.felix</groupId> - <artifactId>maven-bundle-plugin</artifactId> - <configuration> - <supportedProjectTypes> - <supportedProjectType>jar</supportedProjectType> - </supportedProjectTypes> - <instructions> - <Export-Package>brooklyn.*,org.apache.brooklyn.*</Export-Package> - <Import-Package> - !org.apache.brooklyn.rt.felix, - !org.apache.felix.framework, - * - </Import-Package> - </instructions> - </configuration> - </plugin> - </plugins> - <pluginManagement> - <plugins> - <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> - <plugin> - <groupId>org.eclipse.m2e</groupId> - <artifactId>lifecycle-mapping</artifactId> - <version>1.0.0</version> - <configuration> - <lifecycleMappingMetadata> - <pluginExecutions> - <pluginExecution> - <pluginExecutionFilter> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-compiler-plugin</artifactId> - <versionRange>[3.3,)</versionRange> - <goals> - <goal>testCompile</goal> - </goals> - </pluginExecutionFilter> - <action> - <ignore></ignore> - </action> - </pluginExecution> - </pluginExecutions> - </lifecycleMappingMetadata> - </configuration> - </plugin> - </plugins> - </pluginManagement> - </build> -</project> http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d03f254b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java ---------------------------------------------------------------------- diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java deleted file mode 100644 index 1fb4767..0000000 --- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/BrooklynFeatureEnablement.java +++ /dev/null @@ -1,209 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.brooklyn.core; - -import java.util.Map; - -import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode; -import org.apache.brooklyn.core.internal.BrooklynProperties; -import org.apache.brooklyn.core.internal.storage.BrooklynStorage; -import org.apache.brooklyn.util.core.internal.ssh.ShellTool; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.annotations.Beta; -import com.google.common.collect.Maps; - -/** - * For enabling/disabling experimental features. - * They can be enabled via java system properties, or by explicitly calling {@link #setEnablement(String, boolean)}. - * <p> - * For example, start brooklyn with {@code -Dbrooklyn.experimental.feature.policyPersistence=true} - * - * @author aled - */ -@Beta -public class BrooklynFeatureEnablement { - - private static final Logger LOG = LoggerFactory.getLogger(BrooklynFeatureEnablement.class); - - public static final String FEATURE_PROPERTY_PREFIX = "brooklyn.experimental.feature"; - - public static final String FEATURE_POLICY_PERSISTENCE_PROPERTY = FEATURE_PROPERTY_PREFIX+".policyPersistence"; - - public static final String FEATURE_ENRICHER_PERSISTENCE_PROPERTY = FEATURE_PROPERTY_PREFIX+".enricherPersistence"; - - public static final String FEATURE_FEED_PERSISTENCE_PROPERTY = FEATURE_PROPERTY_PREFIX+".feedPersistence"; - - /** whether feeds are automatically registered when set on entities, so that they are persisted */ - public static final String FEATURE_FEED_REGISTRATION_PROPERTY = FEATURE_PROPERTY_PREFIX+".feedRegistration"; - - public static final String FEATURE_CATALOG_PERSISTENCE_PROPERTY = FEATURE_PROPERTY_PREFIX+".catalogPersistence"; - - /** whether the default standby mode is {@link HighAvailabilityMode#HOT_STANDBY} or falling back to the traditional - * {@link HighAvailabilityMode#STANDBY} */ - public static final String FEATURE_DEFAULT_STANDBY_IS_HOT_PROPERTY = FEATURE_PROPERTY_PREFIX+".defaultStandbyIsHot"; - - /** whether to attempt to use {@link BrooklynStorage} (datagrid) as a backing store for data; - * note this is <b>not</b> compatible with {@link #FEATURE_DEFAULT_STANDBY_IS_HOT_PROPERTY} - * which uses a blob/file store and a larger-granularity rebind process than was intended with the datagrid */ - /* not sure if we still even need this? now the rebind/read-only feature reloads on demand from the persistence store; - * the data-grid backing */ - public static final String FEATURE_USE_BROOKLYN_LIVE_OBJECTS_DATAGRID_STORAGE = FEATURE_PROPERTY_PREFIX+".useBrooklynLiveObjectsDatagridStorage"; - - /** - * Renaming threads can really helps with debugging etc; however it's a massive performance hit (2x) - * <p> - * We get 55000 tasks per sec with this off, 28k/s with this on. - * <p> - * Defaults to false if system property is not set. - */ - public static final String FEATURE_RENAME_THREADS = "brooklyn.executionManager.renameThreads"; - - /** - * When rebinding to state created from very old versions, the catalogItemId properties will be missing which - * results in errors when OSGi bundles are used. When enabled the code tries to infer the catalogItemId from - * <ul> - * <li> parent entities - * <li> catalog items matching the type that needs to be deserialized - * <li> iterating through all catalog items and checking if they can provide the needed type - * </ul> - */ - public static final String FEATURE_BACKWARDS_COMPATIBILITY_INFER_CATALOG_ITEM_ON_REBIND = "brooklyn.backwardCompatibility.feature.inferCatalogItemOnRebind"; - - /** - * When rebinding, an entity could reference a catalog item that no longer exists. This option - * will automatically update the catalog item reference to what is inferred as the most - * suitable catalog symbolicName:version. - */ - public static final String FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND = "brooklyn.quickfix.fixDanglingCatalogItemOnRebind"; - - /** - * When executing over ssh, whether to support the "async exec" approach, or only the classic approach. - * - * If this feature is disabled, then even if the {@link ShellTool#PROP_EXEC_ASYNC} is configured it - * will still use the classic ssh approach. - */ - public static final String FEATURE_SSH_ASYNC_EXEC = FEATURE_PROPERTY_PREFIX+".ssh.asyncExec"; - - public static final String FEATURE_VALIDATE_LOCATION_SSH_KEYS = "brooklyn.validate.locationSshKeys"; - - private static final Map<String, Boolean> FEATURE_ENABLEMENTS = Maps.newLinkedHashMap(); - - private static final Object MUTEX = new Object(); - - static void setDefaults() { - // Idea is here one can put experimental features that are *enabled* by default, but - // that can be turned off via system properties, or vice versa. - // Typically this is useful where a feature is deemed risky! - - setDefault(FEATURE_POLICY_PERSISTENCE_PROPERTY, true); - setDefault(FEATURE_ENRICHER_PERSISTENCE_PROPERTY, true); - setDefault(FEATURE_FEED_PERSISTENCE_PROPERTY, true); - setDefault(FEATURE_FEED_REGISTRATION_PROPERTY, false); - setDefault(FEATURE_CATALOG_PERSISTENCE_PROPERTY, true); - setDefault(FEATURE_DEFAULT_STANDBY_IS_HOT_PROPERTY, false); - setDefault(FEATURE_USE_BROOKLYN_LIVE_OBJECTS_DATAGRID_STORAGE, false); - setDefault(FEATURE_RENAME_THREADS, false); - setDefault(FEATURE_BACKWARDS_COMPATIBILITY_INFER_CATALOG_ITEM_ON_REBIND, true); - setDefault(FEATURE_AUTO_FIX_CATALOG_REF_ON_REBIND, false); - setDefault(FEATURE_SSH_ASYNC_EXEC, false); - setDefault(FEATURE_VALIDATE_LOCATION_SSH_KEYS, true); - } - - static { - setDefaults(); - } - - /** - * Initialises the feature-enablement from brooklyn properties. For each - * property, prefer a system-property if present; otherwise use the value - * from brooklyn properties. - */ - public static void init(BrooklynProperties props) { - boolean changed = false; - for (Map.Entry<String, Object> entry : props.asMapWithStringKeys().entrySet()) { - String property = entry.getKey(); - if (property.startsWith(FEATURE_PROPERTY_PREFIX)) { - if (!FEATURE_ENABLEMENTS.containsKey(property)) { - Object rawVal = System.getProperty(property); - if (rawVal == null) { - rawVal = entry.getValue(); - } - boolean val = Boolean.parseBoolean(""+rawVal); - FEATURE_ENABLEMENTS.put(property, val); - - changed = true; - LOG.debug("Init feature enablement of "+property+" set to "+val); - } - } - } - if (!changed) { - LOG.debug("Init feature enablement did nothing, as no settings in brooklyn properties"); - } - } - - public static boolean isEnabled(String property) { - synchronized (MUTEX) { - if (!FEATURE_ENABLEMENTS.containsKey(property)) { - String rawVal = System.getProperty(property); - boolean val = Boolean.parseBoolean(rawVal); - FEATURE_ENABLEMENTS.put(property, val); - } - return FEATURE_ENABLEMENTS.get(property); - } - } - - public static boolean enable(String property) { - return setEnablement(property, true); - } - - public static boolean disable(String property) { - return setEnablement(property, false); - } - - public static boolean setEnablement(String property, boolean val) { - synchronized (MUTEX) { - boolean oldVal = isEnabled(property); - FEATURE_ENABLEMENTS.put(property, val); - return oldVal; - } - } - - public static void setDefault(String property, boolean val) { - synchronized (MUTEX) { - if (!FEATURE_ENABLEMENTS.containsKey(property)) { - String rawVal = System.getProperty(property); - if (rawVal == null) { - FEATURE_ENABLEMENTS.put(property, val); - LOG.debug("Default enablement of "+property+" set to "+val); - } else { - LOG.debug("Not setting default enablement of "+property+" to "+val+", because system property is "+rawVal); - } - } - } - } - - static void clearCache() { - synchronized (MUTEX) { - FEATURE_ENABLEMENTS.clear(); - setDefaults(); - } - } -}
