You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/08/18 15:25:52 UTC
[4/9] incubator-brooklyn git commit: BROOKLYN-162 convert camp-base
and camp-server to org.apache prefix
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/CampServer.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/CampServer.java b/camp/camp-server/src/main/java/io/brooklyn/camp/CampServer.java
deleted file mode 100644
index 9f538c1..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/CampServer.java
+++ /dev/null
@@ -1,185 +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 io.brooklyn.camp;
-
-import io.brooklyn.camp.rest.resource.PlatformRestResource;
-import io.brooklyn.camp.rest.util.DtoFactory;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.EnumSet;
-
-import javax.servlet.DispatcherType;
-
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.handler.ContextHandler;
-import org.eclipse.jetty.servlet.FilterHolder;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.util.thread.QueuedThreadPool;
-import org.eclipse.jetty.webapp.WebAppContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import brooklyn.util.exceptions.Exceptions;
-import brooklyn.util.net.Networking;
-
-import com.google.common.base.Charsets;
-import com.google.common.io.Files;
-import com.sun.jersey.api.core.DefaultResourceConfig;
-import com.sun.jersey.api.core.ResourceConfig;
-import com.sun.jersey.spi.container.servlet.ServletContainer;
-
-public class CampServer {
-
- private static final Logger log = LoggerFactory.getLogger(CampServer.class);
-
- public static final String CAMP_PLATFORM_ATTRIBUTE = CampPlatform.class.getCanonicalName();
- public static final String DTO_FACTORY = DtoFactory.class.getCanonicalName();
-
- private final CampPlatform platform;
- private final String uriBase;
- private DtoFactory dtoFactory;
-
- WebAppContext webAppContext;
- Server server;
-
- public CampServer(CampPlatform platform, String uriBase) {
- this.platform = platform;
- this.uriBase = uriBase;
- }
-
- public CampPlatform getPlatform() {
- return platform;
- }
-
- public String getUriBase() {
- return uriBase;
- }
-
- public WebAppContext getWebAppContext() {
- return webAppContext;
- }
-
- public synchronized DtoFactory getDtoFactory() {
- if (dtoFactory!=null) return dtoFactory;
- dtoFactory = createDtoFactory();
- return dtoFactory;
- }
-
- protected DtoFactory createDtoFactory() {
- return new DtoFactory(getPlatform(), getUriBase());
- }
-
- public synchronized CampServer start() {
- if (webAppContext!=null)
- throw new IllegalStateException("Already started");
-
- webAppContext = new WebAppContext();
- webAppContext.setContextPath("/");
- webAppContext.setAttribute(CAMP_PLATFORM_ATTRIBUTE, getPlatform());
- webAppContext.setAttribute(DTO_FACTORY, getDtoFactory());
- webAppContext.setWar(
- // TODO if there is a GUI or other war...
- //findJsguiWebapp()!=null ? findJsguiWebapp() :
- CampServerUtils.createTempWebDirWithIndexHtml("CAMP REST API <p> (no gui available - " +
- "rest endpoint at <a href=\""+PlatformRestResource.CAMP_URI_PATH+"\">"+PlatformRestResource.CAMP_URI_PATH+"</a>)"));
- CampServerUtils.installAsServletFilter(webAppContext);
-
- server = CampServerUtils.startServer(webAppContext, "CAMP server");
-
- return this;
- }
-
- public synchronized void stop() {
- try {
- server.stop();
- server = null;
- webAppContext.stop();
- webAppContext = null;
- } catch (Exception e) {
- throw Exceptions.propagate(e);
- }
- }
-
- public Integer getPort() {
- if (server==null) return null;
- return server.getConnectors()[0].getLocalPort();
- }
-
- public static class CampServerUtils {
-
- public static void installAsServletFilter(ServletContextHandler context) {
- // TODO security
- // installBrooklynPropertiesSecurityFilter(context);
-
- // now set up the REST servlet resources
- ResourceConfig config = new DefaultResourceConfig();
- // load all our REST API modules, JSON, and Swagger
- for (Object r: CampRestResources.getAllResources())
- config.getSingletons().add(r);
-
- // configure to match empty path, or any thing which looks like a file path with /assets/ and extension html, css, js, or png
- // and treat that as static content
- config.getProperties().put(ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX, "(/?|[^?]*/assets/[^?]+\\.[A-Za-z0-9_]+)");
-
- // and anything which is not matched as a servlet also falls through (but more expensive than a regex check?)
- config.getFeatures().put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, true);
-
- // finally create this as a _filter_ which falls through to a web app or something (optionally)
- FilterHolder filterHolder = new FilterHolder(new ServletContainer(config));
- context.addFilter(filterHolder, "/*", EnumSet.allOf(DispatcherType.class));
- }
-
- public static Server startServer(ContextHandler context, String summary) {
- // FIXME port hardcoded
- int port = Networking.nextAvailablePort(8080);
- Server server = new Server(port);
- server.setHandler(context);
-
- // use a nice name in the thread pool (otherwise this is exactly the same as Server defaults)
- QueuedThreadPool threadPool = new QueuedThreadPool();
- threadPool.setName("camp-jetty-server-"+port+"-"+threadPool.getName());
- server.setThreadPool(threadPool);
-
- try {
- server.start();
- } catch (Exception e) {
- throw Exceptions.propagate(e);
- }
- log.info("CAMP REST server started ("+summary+") on");
- log.info(" http://localhost:"+server.getConnectors()[0].getLocalPort()+"/");
-
- return server;
- }
-
- /** create a directory with a simple index.html so we have some content being served up */
- public static String createTempWebDirWithIndexHtml(String indexHtmlContent) {
- File dir = Files.createTempDir();
- dir.deleteOnExit();
- try {
- Files.write(indexHtmlContent, new File(dir, "index.html"), Charsets.UTF_8);
- } catch (IOException e) {
- Exceptions.propagate(e);
- }
- return dir.getAbsolutePath();
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApiErrorDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApiErrorDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApiErrorDto.java
deleted file mode 100644
index 18b2cba..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApiErrorDto.java
+++ /dev/null
@@ -1,119 +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 io.brooklyn.camp.dto;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import org.codehaus.jackson.annotate.JsonProperty;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.base.Throwables;
-
-/**
- * A simple error message that provides a message and optional details.
- *
- * This class should eventually be replaced with an ErrorMessage object,
- * as described in the CAMP spec.
- */
-public class ApiErrorDto {
-
- public static Builder builder() {
- return new Builder();
- }
-
- /**
- * @return An {@link ApiErrorDto.Builder} whose message is initialised to either the throwable's
- * message or the throwable's class name if the message is null and whose details are
- * initialised to the throwable's stack trace.
- */
- public static Builder fromThrowable(Throwable t) {
- checkNotNull(t, "throwable");
- String message = Optional.fromNullable(t.getMessage())
- .or(t.getClass().getName());
- return builder()
- .message(message)
- .details(Throwables.getStackTraceAsString(t));
- }
-
- public static class Builder {
- private String message;
- private String details;
-
- public Builder message(String message) {
- this.message = checkNotNull(message, "message");
- return this;
- }
-
- public Builder details(String details) {
- this.details = checkNotNull(details, "details");
- return this;
- }
-
- public ApiErrorDto build() {
- return new ApiErrorDto(message, details);
- }
-
- public Builder fromApiErrorDto(ApiErrorDto error) {
- return this
- .message(error.message)
- .details(error.details);
- }
- }
-
- private final String message;
- private final String details;
-
- public ApiErrorDto(
- @JsonProperty("message") String message,
- @JsonProperty("details") String details) {
- this.message = checkNotNull(message, "message");
- this.details = details != null ? details : "";
- }
-
- public String getMessage() {
- return message;
- }
-
- public String getDetails() {
- return details;
- }
-
- @Override
- public boolean equals(Object other) {
- if (this == other) return true;
- if (other == null || getClass() != other.getClass()) return false;
- ApiErrorDto that = ApiErrorDto.class.cast(other);
- return Objects.equal(this.message, that.message) &&
- Objects.equal(this.details, that.details);
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(message, details);
- }
-
- @Override
- public String toString() {
- return Objects.toStringHelper(this)
- .add("message", message)
- .add("details", details)
- .toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApplicationComponentDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApplicationComponentDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApplicationComponentDto.java
deleted file mode 100644
index ae4a68a..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApplicationComponentDto.java
+++ /dev/null
@@ -1,72 +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 io.brooklyn.camp.dto;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.spi.ApplicationComponent;
-import io.brooklyn.camp.spi.Link;
-import io.brooklyn.camp.spi.PlatformComponent;
-
-public class ApplicationComponentDto extends ResourceDto {
-
- // defined as a constant so can be used in Swagger REST API annotations
- public static final String CLASS_NAME = "io.brooklyn.camp.dto.ApplicationComponentDto";
- static { assert CLASS_NAME.equals(ApplicationComponentDto.class.getCanonicalName()); }
-
- protected ApplicationComponentDto() {}
- protected ApplicationComponentDto(DtoFactory dtoFactory, ApplicationComponent x) {
- super(dtoFactory, x);
-
- platformComponents = new ArrayList<LinkDto>();
- for (Link<PlatformComponent> t: x.getPlatformComponents().links()) {
- platformComponents.add(LinkDto.newInstance(dtoFactory, PlatformComponent.class, t));
- }
-
- applicationComponents = new ArrayList<LinkDto>();
- for (Link<ApplicationComponent> t: x.getApplicationComponents().links()) {
- applicationComponents.add(LinkDto.newInstance(dtoFactory, ApplicationComponent.class, t));
- }
- }
-
- private List<LinkDto> platformComponents;
- private List<LinkDto> applicationComponents;
-
- @JsonInclude(Include.NON_EMPTY)
- public List<LinkDto> getPlatformComponents() {
- return platformComponents;
- }
-
- @JsonInclude(Include.NON_EMPTY)
- public List<LinkDto> getApplicationComponents() {
- return applicationComponents;
- }
-
- // --- building ---
-
- public static ApplicationComponentDto newInstance(DtoFactory dtoFactory, ApplicationComponent x) {
- return new ApplicationComponentDto(dtoFactory, x);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApplicationComponentTemplateDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApplicationComponentTemplateDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApplicationComponentTemplateDto.java
deleted file mode 100644
index e3b92f2..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ApplicationComponentTemplateDto.java
+++ /dev/null
@@ -1,44 +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 io.brooklyn.camp.dto;
-
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.spi.ApplicationComponentTemplate;
-
-public class ApplicationComponentTemplateDto extends ResourceDto {
-
- // defined as a constant so can be used in Swagger REST API annotations
- public static final String CLASS_NAME = "io.brooklyn.camp.dto.ApplicationComponentTemplateDto";
- static { assert CLASS_NAME.equals(ApplicationComponentTemplateDto.class.getCanonicalName()); }
-
- protected ApplicationComponentTemplateDto() {}
- protected ApplicationComponentTemplateDto(DtoFactory dtoFactory, ApplicationComponentTemplate x) {
- super(dtoFactory, x);
- // TODO set addl ACT fields
- }
-
- // TODO add addl ACT fields
-
- // --- building ---
-
- public static ApplicationComponentTemplateDto newInstance(DtoFactory dtoFactory, ApplicationComponentTemplate x) {
- return new ApplicationComponentTemplateDto(dtoFactory, x);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/AssemblyDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/AssemblyDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/AssemblyDto.java
deleted file mode 100644
index 9f36ce6..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/AssemblyDto.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 io.brooklyn.camp.dto;
-
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.spi.ApplicationComponent;
-import io.brooklyn.camp.spi.Assembly;
-import io.brooklyn.camp.spi.Link;
-import io.brooklyn.camp.spi.PlatformComponent;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-
-public class AssemblyDto extends ResourceDto {
-
- // defined as a constant so can be used in Swagger REST API annotations
- public static final String CLASS_NAME = "io.brooklyn.camp.dto.AssemblyDto";
- static { assert CLASS_NAME.equals(AssemblyDto.class.getCanonicalName()); }
-
- protected AssemblyDto() {}
- protected AssemblyDto(DtoFactory dtoFactory, Assembly x) {
- super(dtoFactory, x);
-
- platformComponents = new ArrayList<LinkDto>();
- for (Link<PlatformComponent> t: x.getPlatformComponents().links()) {
- platformComponents.add(LinkDto.newInstance(dtoFactory, PlatformComponent.class, t));
- }
-
- applicationComponents = new ArrayList<LinkDto>();
- for (Link<ApplicationComponent> t: x.getApplicationComponents().links()) {
- applicationComponents.add(LinkDto.newInstance(dtoFactory, ApplicationComponent.class, t));
- }
- }
-
- private List<LinkDto> platformComponents;
- private List<LinkDto> applicationComponents;
-
- // TODO addl AssemblyTemplate fields
-// "parameterDefinitionUri": URI,
-// "pdpUri" : URI ?
-
- @JsonInclude(Include.NON_EMPTY)
- public List<LinkDto> getPlatformComponents() {
- return platformComponents;
- }
-
- @JsonInclude(Include.NON_EMPTY)
- public List<LinkDto> getApplicationComponents() {
- return applicationComponents;
- }
-
- // --- building ---
-
- public static AssemblyDto newInstance(DtoFactory dtoFactory, Assembly x) {
- return new AssemblyDto(dtoFactory, x);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/AssemblyTemplateDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/AssemblyTemplateDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/AssemblyTemplateDto.java
deleted file mode 100644
index 3aca985..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/AssemblyTemplateDto.java
+++ /dev/null
@@ -1,72 +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 io.brooklyn.camp.dto;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.spi.ApplicationComponentTemplate;
-import io.brooklyn.camp.spi.AssemblyTemplate;
-import io.brooklyn.camp.spi.Link;
-import io.brooklyn.camp.spi.PlatformComponentTemplate;
-
-public class AssemblyTemplateDto extends ResourceDto {
-
- // defined as a constant so can be used in Swagger REST API annotations
- public static final String CLASS_NAME = "io.brooklyn.camp.dto.AssemblyTemplateDto";
- static { assert CLASS_NAME.equals(AssemblyTemplateDto.class.getCanonicalName()); }
-
- protected AssemblyTemplateDto() {}
- protected AssemblyTemplateDto(DtoFactory dtoFactory, AssemblyTemplate x) {
- super(dtoFactory, x);
-
- platformComponentTemplates = new ArrayList<LinkDto>();
- for (Link<PlatformComponentTemplate> t: x.getPlatformComponentTemplates().links()) {
- platformComponentTemplates.add(LinkDto.newInstance(dtoFactory, PlatformComponentTemplate.class, t));
- }
-
- applicationComponentTemplates = new ArrayList<LinkDto>();
- for (Link<ApplicationComponentTemplate> t: x.getApplicationComponentTemplates().links()) {
- applicationComponentTemplates.add(LinkDto.newInstance(dtoFactory, ApplicationComponentTemplate.class, t));
- }
- }
-
- private List<LinkDto> platformComponentTemplates;
- private List<LinkDto> applicationComponentTemplates;
-
- // TODO addl AssemblyTemplate fields
-// "parameterDefinitionUri": URI,
-// "pdpUri" : URI ?
-
- public List<LinkDto> getPlatformComponentTemplates() {
- return platformComponentTemplates;
- }
-
- public List<LinkDto> getApplicationComponentTemplates() {
- return applicationComponentTemplates;
- }
-
- // --- building ---
-
- public static AssemblyTemplateDto newInstance(DtoFactory dtoFactory, AssemblyTemplate x) {
- return new AssemblyTemplateDto(dtoFactory, x);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/DtoBase.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/DtoBase.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/DtoBase.java
deleted file mode 100644
index f846eee..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/DtoBase.java
+++ /dev/null
@@ -1,31 +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 io.brooklyn.camp.dto;
-
-import org.apache.commons.lang3.builder.EqualsBuilder;
-import org.apache.commons.lang3.builder.HashCodeBuilder;
-import org.apache.commons.lang3.builder.ToStringBuilder;
-
-public class DtoBase {
-
- @Override public String toString() { return ToStringBuilder.reflectionToString(this); }
- @Override public boolean equals(Object obj) { return EqualsBuilder.reflectionEquals(this, obj); }
- @Override public int hashCode() { return HashCodeBuilder.reflectionHashCode(this); }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/DtoCustomAttributes.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/DtoCustomAttributes.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/DtoCustomAttributes.java
deleted file mode 100644
index 38b9d94..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/DtoCustomAttributes.java
+++ /dev/null
@@ -1,66 +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 io.brooklyn.camp.dto;
-
-import java.util.Map;
-
-import brooklyn.util.collections.MutableMap;
-
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonAnySetter;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.google.common.collect.ImmutableMap;
-
-public class DtoCustomAttributes extends DtoBase {
-
- private Map<String,Object> customAttributes = new MutableMap<String, Object>();
-
- protected DtoCustomAttributes() {}
-
- public DtoCustomAttributes(Map<String,?> customAttributes) {
- this.customAttributes = customAttributes==null ? ImmutableMap.<String, Object>of() : ImmutableMap.copyOf(customAttributes);
- }
-
- @JsonIgnore
- public Map<String, Object> getCustomAttributes() {
- return customAttributes;
- }
-
- // --- json ---
-
- @JsonInclude(Include.NON_EMPTY)
- @JsonAnyGetter
- private Map<String,Object> any() {
- return customAttributes;
- }
- @JsonAnySetter
- private void set(String name, Object value) {
- customAttributes.put(name, value);
- }
-
- // --- building ---
-
- protected void newInstanceCustomAttributes(Map<String,?> customAttributes) {
- if (customAttributes!=null)
- this.customAttributes.putAll(customAttributes);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/LinkDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/LinkDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/LinkDto.java
deleted file mode 100644
index e6dc964..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/LinkDto.java
+++ /dev/null
@@ -1,72 +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 io.brooklyn.camp.dto;
-
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.spi.AbstractResource;
-import io.brooklyn.camp.spi.Link;
-
-import java.util.Map;
-
-public class LinkDto extends DtoCustomAttributes {
-
- // defined as a constant so can be used in Swagger REST API annotations
- public static final String CLASS_NAME = "io.brooklyn.camp.dto.LinkDto";
- static { assert CLASS_NAME.equals(LinkDto.class.getCanonicalName()); }
-
- private String href;
- private String targetName;
-
- protected LinkDto() {}
-
- public String getHref() {
- return href;
- }
-
- public String getTargetName() {
- return targetName;
- }
-
- // --- building ---
-
- public static LinkDto newInstance(DtoFactory dtoFactory, Class<? extends AbstractResource> targetType, Link<?> x) {
- return new LinkDto().newInstanceInitialization(dtoFactory, targetType, x);
- }
-
- protected LinkDto newInstanceInitialization(DtoFactory dtoFactory, Class<? extends AbstractResource> targetType, Link<?> x) {
- targetName = x.getName();
-
- href = dtoFactory.uri(targetType, x.getId());
- return this;
- }
-
- public static LinkDto newInstance(String href, String targetName) {
- LinkDto x = new LinkDto();
- x.href = href;
- x.targetName = targetName;
- return x;
- }
-
- public static LinkDto newInstance(String href, String targetName, Map<String,?> customAttributes) {
- LinkDto x = newInstance(href, targetName);
- x.newInstanceCustomAttributes(customAttributes);
- return x;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformComponentDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformComponentDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformComponentDto.java
deleted file mode 100644
index d9d1c85..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformComponentDto.java
+++ /dev/null
@@ -1,82 +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 io.brooklyn.camp.dto;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.spi.ApplicationComponent;
-import io.brooklyn.camp.spi.Link;
-import io.brooklyn.camp.spi.PlatformComponent;
-
-public class PlatformComponentDto extends ResourceDto {
-
- // defined as a constant so can be used in Swagger REST API annotations
- public static final String CLASS_NAME = "io.brooklyn.camp.dto.PlatformComponentDto";
- static { assert CLASS_NAME.equals(PlatformComponentDto.class.getCanonicalName()); }
-
- protected PlatformComponentDto() {}
- protected PlatformComponentDto(DtoFactory dtoFactory, PlatformComponent x) {
- super(dtoFactory, x);
- setExternalManagementUri(x.getExternalManagementUri());
- platformComponents = new ArrayList<LinkDto>();
- for (Link<PlatformComponent> t: x.getPlatformComponents().links()) {
- platformComponents.add(LinkDto.newInstance(dtoFactory, PlatformComponent.class, t));
- }
-
- applicationComponents = new ArrayList<LinkDto>();
- for (Link<ApplicationComponent> t: x.getApplicationComponents().links()) {
- applicationComponents.add(LinkDto.newInstance(dtoFactory, ApplicationComponent.class, t));
- }
- }
-
- private List<LinkDto> platformComponents;
- private List<LinkDto> applicationComponents;
-
- private String externalManagementUri;
-
- @JsonInclude(Include.NON_EMPTY)
- public List<LinkDto> getPlatformComponents() {
- return platformComponents;
- }
-
- @JsonInclude(Include.NON_EMPTY)
- public List<LinkDto> getApplicationComponents() {
- return applicationComponents;
- }
-
- @JsonInclude(Include.NON_EMPTY)
- public String getExternalManagementUri() {
- return externalManagementUri;
- }
- private void setExternalManagementUri(String externalManagementUri) {
- this.externalManagementUri = externalManagementUri;
- }
-
- // --- building ---
-
- public static PlatformComponentDto newInstance(DtoFactory dtoFactory, PlatformComponent x) {
- return new PlatformComponentDto(dtoFactory, x);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformComponentTemplateDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformComponentTemplateDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformComponentTemplateDto.java
deleted file mode 100644
index 252e9f6..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformComponentTemplateDto.java
+++ /dev/null
@@ -1,44 +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 io.brooklyn.camp.dto;
-
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.spi.PlatformComponentTemplate;
-
-public class PlatformComponentTemplateDto extends ResourceDto {
-
- // defined as a constant so can be used in Swagger REST API annotations
- public static final String CLASS_NAME = "io.brooklyn.camp.dto.PlatformComponentTemplateDto";
- static { assert CLASS_NAME.equals(PlatformComponentTemplateDto.class.getCanonicalName()); }
-
- protected PlatformComponentTemplateDto() {}
- protected PlatformComponentTemplateDto(DtoFactory dtoFactory, PlatformComponentTemplate x) {
- super(dtoFactory, x);
- // TODO set addl PCT fields
- }
-
- // TODO add addl PCT fields
-
- // --- building ---
-
- public static PlatformComponentTemplateDto newInstance(DtoFactory dtoFactory, PlatformComponentTemplate x) {
- return new PlatformComponentTemplateDto(dtoFactory, x);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformDto.java
deleted file mode 100644
index 0daf3ac..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/PlatformDto.java
+++ /dev/null
@@ -1,131 +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 io.brooklyn.camp.dto;
-
-import io.brooklyn.camp.rest.resource.ApidocRestResource;
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.spi.ApplicationComponent;
-import io.brooklyn.camp.spi.ApplicationComponentTemplate;
-import io.brooklyn.camp.spi.Assembly;
-import io.brooklyn.camp.spi.AssemblyTemplate;
-import io.brooklyn.camp.spi.Link;
-import io.brooklyn.camp.spi.PlatformComponent;
-import io.brooklyn.camp.spi.PlatformComponentTemplate;
-import io.brooklyn.camp.spi.PlatformRootSummary;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-
-public class PlatformDto extends ResourceDto {
-
- // defined as a constant so can be used in Swagger REST API annotations
- public static final String CLASS_NAME = "io.brooklyn.camp.dto.PlatformDto";
- static { assert CLASS_NAME.equals(PlatformDto.class.getCanonicalName()); }
-
- protected PlatformDto() {}
- protected PlatformDto(DtoFactory dtoFactory, PlatformRootSummary x) {
- super(dtoFactory, x);
- platformComponentTemplates = new ArrayList<LinkDto>();
- for (Link<PlatformComponentTemplate> t: dtoFactory.getPlatform().platformComponentTemplates().links()) {
- platformComponentTemplates.add(LinkDto.newInstance(dtoFactory, PlatformComponentTemplate.class, t));
- }
-
- applicationComponentTemplates = new ArrayList<LinkDto>();
- for (Link<ApplicationComponentTemplate> t: dtoFactory.getPlatform().applicationComponentTemplates().links()) {
- applicationComponentTemplates.add(LinkDto.newInstance(dtoFactory, ApplicationComponentTemplate.class, t));
- }
-
- assemblyTemplates = new ArrayList<LinkDto>();
- for (Link<AssemblyTemplate> t: dtoFactory.getPlatform().assemblyTemplates().links()) {
- assemblyTemplates.add(LinkDto.newInstance(dtoFactory, AssemblyTemplate.class, t));
- }
-
- platformComponents = new ArrayList<LinkDto>();
- for (Link<PlatformComponent> t: dtoFactory.getPlatform().platformComponents().links()) {
- platformComponents.add(LinkDto.newInstance(dtoFactory, PlatformComponent.class, t));
- }
-
- applicationComponents = new ArrayList<LinkDto>();
- for (Link<ApplicationComponent> t: dtoFactory.getPlatform().applicationComponents().links()) {
- applicationComponents.add(LinkDto.newInstance(dtoFactory, ApplicationComponent.class, t));
- }
-
- assemblies = new ArrayList<LinkDto>();
- for (Link<Assembly> t: dtoFactory.getPlatform().assemblies().links()) {
- assemblies.add(LinkDto.newInstance(dtoFactory, Assembly.class, t));
- }
-
- // TODO set custom fields
-
- apidoc = LinkDto.newInstance(
- dtoFactory.getUriFactory().uriOfRestResource(ApidocRestResource.class),
- "API documentation");
- }
-
- // TODO add custom fields
- private List<LinkDto> assemblyTemplates;
- private List<LinkDto> platformComponentTemplates;
- private List<LinkDto> applicationComponentTemplates;
- private List<LinkDto> assemblies;
- private List<LinkDto> platformComponents;
- private List<LinkDto> applicationComponents;
-
- // non-CAMP, but useful
- private LinkDto apidoc;
-
- public List<LinkDto> getAssemblyTemplates() {
- return assemblyTemplates;
- }
-
- public List<LinkDto> getPlatformComponentTemplates() {
- return platformComponentTemplates;
- }
-
- public List<LinkDto> getApplicationComponentTemplates() {
- return applicationComponentTemplates;
- }
-
- public List<LinkDto> getAssemblies() {
- return assemblies;
- }
-
- @JsonInclude(Include.NON_EMPTY)
- public List<LinkDto> getPlatformComponents() {
- return platformComponents;
- }
-
- @JsonInclude(Include.NON_EMPTY)
- public List<LinkDto> getApplicationComponents() {
- return applicationComponents;
- }
-
- public LinkDto getApidoc() {
- return apidoc;
- }
-
- // --- building ---
-
- public static PlatformDto newInstance(DtoFactory dtoFactory, PlatformRootSummary x) {
- return new PlatformDto(dtoFactory, x);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ResourceDto.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ResourceDto.java b/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ResourceDto.java
deleted file mode 100644
index 5383cf5..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/dto/ResourceDto.java
+++ /dev/null
@@ -1,112 +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 io.brooklyn.camp.dto;
-
-import io.brooklyn.camp.commontypes.RepresentationSkew;
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.spi.AbstractResource;
-
-import java.util.Date;
-import java.util.List;
-
-import brooklyn.util.time.Time;
-
-import com.fasterxml.jackson.annotation.JsonGetter;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.fasterxml.jackson.annotation.JsonInclude.Include;
-import com.fasterxml.jackson.annotation.JsonSetter;
-import com.fasterxml.jackson.databind.util.ISO8601Utils;
-
-public class ResourceDto extends DtoCustomAttributes {
-
- protected ResourceDto() {}
- protected ResourceDto(DtoFactory dtoFactory, AbstractResource x) {
- type = x.getType();
- name = x.getName();
-
- description = x.getDescription();
- setCreated(x.getCreated());
- tags = x.getTags();
- representationSkew = x.getRepresentationSkew();
-
- if (x.getCustomAttributes()!=null && !x.getCustomAttributes().isEmpty())
- newInstanceCustomAttributes(x.getCustomAttributes());
-
- uri = dtoFactory.uri(x);
- }
-
- private String uri;
- private String type;
-
- private String name;
- private String description;
- private Date created;
- private List<String> tags;
- private RepresentationSkew representationSkew;
-
- public String getUri() {
- return uri;
- }
-
- public String getName() {
- return name;
- }
-
- @JsonInclude(Include.NON_NULL)
- public String getDescription() {
- return description;
- }
-
- @JsonGetter("created")
- public String getCreatedAsString() {
- return created==null ? null : ISO8601Utils.format(created);
- }
-
- @JsonSetter
- private void setCreated(Date created) {
- this.created = Time.dropMilliseconds(created);
- }
-
- @JsonIgnore
- public Date getCreated() {
- return created;
- }
-
- @JsonInclude(Include.NON_EMPTY)
- public List<String> getTags() {
- return tags;
- }
-
- public String getType() {
- return type;
- }
-
- @JsonInclude(Include.NON_NULL)
- public RepresentationSkew getRepresentationSkew() {
- return representationSkew;
- }
-
- // --- building ---
-
- public static ResourceDto newInstance(DtoFactory dtoFactory, AbstractResource x) {
- return new ResourceDto(dtoFactory, x);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AbstractCampRestResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AbstractCampRestResource.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AbstractCampRestResource.java
deleted file mode 100644
index dcc5c14..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AbstractCampRestResource.java
+++ /dev/null
@@ -1,56 +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 io.brooklyn.camp.rest.resource;
-
-import io.brooklyn.camp.CampPlatform;
-import io.brooklyn.camp.rest.util.CampRestContext;
-import io.brooklyn.camp.rest.util.DtoFactory;
-import io.brooklyn.camp.rest.util.WebResourceUtils;
-import io.brooklyn.camp.spi.AbstractResource;
-import io.brooklyn.camp.spi.collection.ResourceLookup;
-
-import javax.servlet.ServletContext;
-import javax.ws.rs.core.Context;
-
-public abstract class AbstractCampRestResource {
-
- // can be injected by jersey when not injected manually
- // (seems there is no way to make this optional so note it _must_ be injected; if needed
- // see notes on workarounds for test frameworks in original AbstractBrooklynRestResource)
- @Context ServletContext servletContext;
-
- private CampRestContext campRestContext;
-
- public synchronized CampRestContext context() {
- if (campRestContext!=null) return campRestContext;
- campRestContext = new CampRestContext(servletContext);
- return campRestContext;
- }
-
- public CampPlatform camp() { return context().camp(); }
- public DtoFactory dto() { return context().dto(); }
-
- public static <T extends AbstractResource> T lookup(ResourceLookup<T> list, String id) {
- T result = list.get(id);
- if (result==null)
- throw WebResourceUtils.notFound("No such element: %s", id);
- return result;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApidocRestResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApidocRestResource.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApidocRestResource.java
deleted file mode 100644
index 98d73c5..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApidocRestResource.java
+++ /dev/null
@@ -1,31 +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 io.brooklyn.camp.rest.resource;
-
-import javax.ws.rs.Path;
-
-import org.apache.brooklyn.rest.apidoc.Apidoc;
-
-@Path(ApidocRestResource.API_URI_PATH)
-@Apidoc("Web API Documentation")
-public class ApidocRestResource extends org.apache.brooklyn.rest.apidoc.ApidocResource {
-
- public static final String API_URI_PATH = PlatformRestResource.CAMP_URI_PATH + "/apidoc";
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApplicationComponentRestResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApplicationComponentRestResource.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApplicationComponentRestResource.java
deleted file mode 100644
index e2f26e5..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApplicationComponentRestResource.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 io.brooklyn.camp.rest.resource;
-
-import io.brooklyn.camp.dto.ApplicationComponentDto;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-
-import org.apache.brooklyn.rest.apidoc.Apidoc;
-
-import com.wordnik.swagger.core.ApiOperation;
-import com.wordnik.swagger.core.ApiParam;
-
-@Path(ApplicationComponentRestResource.URI_PATH)
-@Apidoc("Application Component resources")
-@Produces("application/json")
-public class ApplicationComponentRestResource extends AbstractCampRestResource {
-
- public static final String URI_PATH = PlatformRestResource.CAMP_URI_PATH + "/application-components";
-
- @Path("/{id}")
- @ApiOperation(value = "Get a specific application component",
- responseClass = ApplicationComponentDto.CLASS_NAME)
- @GET
- public ApplicationComponentDto get(
- @ApiParam(value = "ID of item being retrieved", required = true)
- @PathParam("id") String id) {
- return dto().adapt(lookup(camp().applicationComponents(), id));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApplicationComponentTemplateRestResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApplicationComponentTemplateRestResource.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApplicationComponentTemplateRestResource.java
deleted file mode 100644
index 992a579..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/ApplicationComponentTemplateRestResource.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 io.brooklyn.camp.rest.resource;
-
-import io.brooklyn.camp.dto.ApplicationComponentTemplateDto;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-
-import org.apache.brooklyn.rest.apidoc.Apidoc;
-
-import com.wordnik.swagger.core.ApiOperation;
-import com.wordnik.swagger.core.ApiParam;
-
-@Path(ApplicationComponentTemplateRestResource.URI_PATH)
-@Apidoc("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",
- responseClass = ApplicationComponentTemplateDto.CLASS_NAME)
- @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/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AssemblyRestResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AssemblyRestResource.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AssemblyRestResource.java
deleted file mode 100644
index 721abea..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AssemblyRestResource.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 io.brooklyn.camp.rest.resource;
-
-import io.brooklyn.camp.dto.AssemblyDto;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-
-import org.apache.brooklyn.rest.apidoc.Apidoc;
-
-import com.wordnik.swagger.core.ApiOperation;
-import com.wordnik.swagger.core.ApiParam;
-
-@Path(AssemblyRestResource.URI_PATH)
-@Apidoc("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",
- responseClass = AssemblyDto.CLASS_NAME)
- @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/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AssemblyTemplateRestResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AssemblyTemplateRestResource.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AssemblyTemplateRestResource.java
deleted file mode 100644
index 104295c..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/AssemblyTemplateRestResource.java
+++ /dev/null
@@ -1,88 +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 io.brooklyn.camp.rest.resource;
-
-import io.brooklyn.camp.dto.AssemblyTemplateDto;
-import io.brooklyn.camp.spi.Assembly;
-import io.brooklyn.camp.spi.AssemblyTemplate;
-
-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.rest.apidoc.Apidoc;
-import brooklyn.util.exceptions.Exceptions;
-
-import com.wordnik.swagger.core.ApiOperation;
-import com.wordnik.swagger.core.ApiParam;
-
-@Path(AssemblyTemplateRestResource.URI_PATH)
-@Apidoc("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",
- responseClass = AssemblyTemplateDto.CLASS_NAME)
- @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/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformComponentRestResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformComponentRestResource.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformComponentRestResource.java
deleted file mode 100644
index a2718f6..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformComponentRestResource.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 io.brooklyn.camp.rest.resource;
-
-import io.brooklyn.camp.dto.PlatformComponentDto;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-
-import org.apache.brooklyn.rest.apidoc.Apidoc;
-
-import com.wordnik.swagger.core.ApiOperation;
-import com.wordnik.swagger.core.ApiParam;
-
-@Path(PlatformComponentRestResource.URI_PATH)
-@Apidoc("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",
- responseClass = PlatformComponentDto.CLASS_NAME)
- @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/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformComponentTemplateRestResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformComponentTemplateRestResource.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformComponentTemplateRestResource.java
deleted file mode 100644
index 9d2112d..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformComponentTemplateRestResource.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 io.brooklyn.camp.rest.resource;
-
-import io.brooklyn.camp.dto.PlatformComponentTemplateDto;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-
-import org.apache.brooklyn.rest.apidoc.Apidoc;
-
-import com.wordnik.swagger.core.ApiOperation;
-import com.wordnik.swagger.core.ApiParam;
-
-@Path(PlatformComponentTemplateRestResource.URI_PATH)
-@Apidoc("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",
- responseClass = PlatformComponentTemplateDto.CLASS_NAME)
- @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/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformRestResource.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformRestResource.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformRestResource.java
deleted file mode 100644
index edf4bc5..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/resource/PlatformRestResource.java
+++ /dev/null
@@ -1,89 +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 io.brooklyn.camp.rest.resource;
-
-import io.brooklyn.camp.dto.PlatformDto;
-import io.brooklyn.camp.rest.util.WebResourceUtils;
-import io.brooklyn.camp.spi.AssemblyTemplate;
-
-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.rest.apidoc.Apidoc;
-
-import com.wordnik.swagger.core.ApiOperation;
-
-//import io.brooklyn.camp.rest.apidoc.Apidoc;
-
-@Path(PlatformRestResource.CAMP_URI_PATH)
-@Apidoc("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",
- responseClass = PlatformDto.CLASS_NAME)
- @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/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/CampJsons.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/CampJsons.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/CampJsons.java
deleted file mode 100644
index 1cb39bd..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/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 io.brooklyn.camp.rest.util;
-
-import 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/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/CampRestContext.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/CampRestContext.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/CampRestContext.java
deleted file mode 100644
index 817a621..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/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 io.brooklyn.camp.rest.util;
-
-import javax.servlet.ServletContext;
-
-import com.google.common.base.Preconditions;
-
-import io.brooklyn.camp.CampPlatform;
-import io.brooklyn.camp.CampServer;
-
-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/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/CampRestGuavas.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/CampRestGuavas.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/CampRestGuavas.java
deleted file mode 100644
index ac475d9..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/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 io.brooklyn.camp.rest.util;
-
-import io.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/incubator-brooklyn/blob/7d782f34/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/DtoFactory.java
----------------------------------------------------------------------
diff --git a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/DtoFactory.java b/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/DtoFactory.java
deleted file mode 100644
index ccb00b9..0000000
--- a/camp/camp-server/src/main/java/io/brooklyn/camp/rest/util/DtoFactory.java
+++ /dev/null
@@ -1,176 +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 io.brooklyn.camp.rest.util;
-
-import io.brooklyn.camp.CampPlatform;
-import io.brooklyn.camp.dto.ApplicationComponentDto;
-import io.brooklyn.camp.dto.ApplicationComponentTemplateDto;
-import io.brooklyn.camp.dto.AssemblyDto;
-import io.brooklyn.camp.dto.AssemblyTemplateDto;
-import io.brooklyn.camp.dto.PlatformComponentDto;
-import io.brooklyn.camp.dto.PlatformComponentTemplateDto;
-import io.brooklyn.camp.dto.PlatformDto;
-import io.brooklyn.camp.rest.resource.AbstractCampRestResource;
-import io.brooklyn.camp.rest.resource.ApplicationComponentRestResource;
-import io.brooklyn.camp.rest.resource.ApplicationComponentTemplateRestResource;
-import io.brooklyn.camp.rest.resource.AssemblyRestResource;
-import io.brooklyn.camp.rest.resource.AssemblyTemplateRestResource;
-import io.brooklyn.camp.rest.resource.PlatformComponentRestResource;
-import io.brooklyn.camp.rest.resource.PlatformComponentTemplateRestResource;
-import io.brooklyn.camp.rest.resource.PlatformRestResource;
-import io.brooklyn.camp.spi.AbstractResource;
-import io.brooklyn.camp.spi.ApplicationComponent;
-import io.brooklyn.camp.spi.ApplicationComponentTemplate;
-import io.brooklyn.camp.spi.Assembly;
-import io.brooklyn.camp.spi.AssemblyTemplate;
-import io.brooklyn.camp.spi.PlatformComponent;
-import io.brooklyn.camp.spi.PlatformComponentTemplate;
-import io.brooklyn.camp.spi.PlatformRootSummary;
-
-import java.util.Map;
-
-import javax.ws.rs.Path;
-
-import brooklyn.util.collections.MutableMap;
-import 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());
- }
-
-
- }
-
-}