Skip to content

Commit

Permalink
Merge pull request #38 from orange-cloudfoundry/36_polish_executable_…
Browse files Browse the repository at this point in the history
…specifications

Polish executable specifications
  • Loading branch information
s-bortolussi authored Feb 1, 2017
2 parents d8a04fb + 1420433 commit 96e8d0f
Show file tree
Hide file tree
Showing 46 changed files with 872 additions and 785 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.orange.servicebroker.staticcreds.config;

import com.orange.servicebroker.staticcreds.domain.Service;
import com.orange.servicebroker.staticcreds.domain.ServiceProperties;
import com.orange.servicebroker.staticcreds.domain.ServiceRepository;
import com.orange.servicebroker.staticcreds.infrastructure.ServiceMapper;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -19,8 +19,8 @@ public class CatalogConfig {

@Bean
public Catalog catalog() {
final List<Service> services = serviceRepository.findAll();
final List<ServiceDefinition> serviceDefinitions = ServiceMapper.toServiceDefinitions(services);
final List<ServiceProperties> serviceProperties = serviceRepository.findAll();
final List<ServiceDefinition> serviceDefinitions = ServiceMapper.toServiceDefinitions(serviceProperties);
return new Catalog(serviceDefinitions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
@Setter
@ToString
@EqualsAndHashCode
public class Amount {
private float usd;
public class AmountProperties {
private float usd;
private float eur;

public Amount() {
}
public AmountProperties() {
}

public Amount(float usd, float eur) {
this.usd = usd;
public AmountProperties(float usd, float eur) {
this.usd = usd;
this.eur = eur;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
@Setter
@ToString
@EqualsAndHashCode
public class Cost {
public class CostProperties {

private Amount amount;
private String unit;
private AmountProperties amount;
private String unit;

public Cost() {
}
public CostProperties() {
}

public Cost(Amount amount, String unit) {
this.amount = amount;
public CostProperties(AmountProperties amount, String unit) {
this.amount = amount;
this.unit = unit;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
@Setter
@ToString
@EqualsAndHashCode
public class PlanMetadata {
public class PlanMetadataProperties {
private String[] bullets;
private Cost[] costs;
private CostProperties[] costs;
private String displayName;

public Map<String, Object> toMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Setter
@ToString
@EqualsAndHashCode
public class Plan {
public class PlanProperties {

public static final String NO_ID_ERROR = "Invalid configuration. No id has been set for plan";

Expand All @@ -37,7 +37,7 @@ public class Plan {
private String description;

@Valid
private PlanMetadata metadata = new PlanMetadata();
private PlanMetadataProperties metadata = new PlanMetadataProperties();

@NotNull
private Boolean free = FREE_DEFAULT;
Expand All @@ -62,10 +62,10 @@ public class Plan {
*/
private List<VolumeMountProperties> volumeMounts = new ArrayList<>();

public Plan() {
public PlanProperties() {
}

public Plan(String id) {
public PlanProperties(String id) {
this.id = id;
}

Expand All @@ -83,7 +83,7 @@ public Optional<Map<String, Object>> getFullCredentials() {
public void setMetadata(String metadataJson) {
ObjectMapper mapper = new ObjectMapper();
try {
this.metadata = mapper.readValue(metadataJson, PlanMetadata.class);
this.metadata = mapper.readValue(metadataJson, PlanMetadataProperties.class);
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,26 @@
@Component
@ConfigurationProperties
@ToString
public class CatalogSettings {
public class ServiceBrokerProperties {

public static final String NO_SERVICE_ERROR = "Invalid configuration. No service has been defined";
@NotNull
@Size(min = 1, message = NO_SERVICE_ERROR)
@Valid
private Map<String, Service> services = new HashMap<>();
private Map<String, ServiceProperties> services = new HashMap<>();

public CatalogSettings() {
public ServiceBrokerProperties() {
}

public CatalogSettings(Map<String, Service> services) {
public ServiceBrokerProperties(Map<String, ServiceProperties> services) {
this.services = services;
}

public Map<String, Service> getServices() {
public Map<String, ServiceProperties> getServices() {
return services;
}

public void setServices(Map<String, Service> services) {
public void setServices(Map<String, ServiceProperties> services) {
this.services = services;
}

Expand All @@ -56,8 +56,8 @@ public void init() {
}

private void assertPlanCredentialsExists() {
final Predicate<Plan> planWithoutCredential = plan -> !plan.getFullCredentials().isPresent();
final Predicate<Service> serviceWithoutCredential = service -> !service.getFullCredentials().isPresent();
final Predicate<PlanProperties> planWithoutCredential = plan -> !plan.getFullCredentials().isPresent();
final Predicate<ServiceProperties> serviceWithoutCredential = service -> !service.getFullCredentials().isPresent();

services.values().stream()
.filter(serviceWithoutCredential)
Expand Down Expand Up @@ -87,56 +87,56 @@ private void assertVolumeMountRequiresExists() {
});
}

private boolean syslogDrainUrlHasText(Service service, Plan plan) {
return plan.getSyslogDrainUrl() != null || service.getSyslogDrainUrl() != null;
private boolean syslogDrainUrlHasText(ServiceProperties serviceProperties, PlanProperties planProperties) {
return planProperties.getSyslogDrainUrl() != null || serviceProperties.getSyslogDrainUrl() != null;
}

private boolean requiresSyslogDrainUrlNotPresent(Service service) {
return service.getRequires() == null || !service.getRequires().contains(ServiceDefinitionRequires.SERVICE_REQUIRES_SYSLOG_DRAIN.toString());
private boolean requiresSyslogDrainUrlNotPresent(ServiceProperties serviceProperties) {
return serviceProperties.getRequires() == null || !serviceProperties.getRequires().contains(ServiceDefinitionRequires.SERVICE_REQUIRES_SYSLOG_DRAIN.toString());
}

private boolean volumeMountExists(Service service, Plan plan) {
return (plan.getVolumeMounts() != null && !plan.getVolumeMounts().isEmpty()) || (service.getVolumeMounts() != null && !service.getVolumeMounts().isEmpty());
private boolean volumeMountExists(ServiceProperties serviceProperties, PlanProperties planProperties) {
return (planProperties.getVolumeMounts() != null && !planProperties.getVolumeMounts().isEmpty()) || (serviceProperties.getVolumeMounts() != null && !serviceProperties.getVolumeMounts().isEmpty());
}

private boolean requiresVolumeMountNotPresent(Service service) {
return service.getRequires() == null || !service.getRequires().contains(ServiceDefinitionRequires.SERVICE_REQUIRES_VOLUME_MOUNT.toString());
private boolean requiresVolumeMountNotPresent(ServiceProperties serviceProperties) {
return serviceProperties.getRequires() == null || !serviceProperties.getRequires().contains(ServiceDefinitionRequires.SERVICE_REQUIRES_VOLUME_MOUNT.toString());
}

private void setDefaultServiceDisplayName() {
services.keySet().forEach(serviceKey -> {
final Service service = services.get(serviceKey);
//no service id set
final ServiceMetadata metadata = service.getMetadata();
//force id with service name
final ServiceProperties serviceProperties = services.get(serviceKey);
//no serviceProperties id set
final ServiceMetadataProperties metadata = serviceProperties.getMetadata();
//force id with serviceProperties name
if (metadata.getDisplayName() == null || metadata.getDisplayName().isEmpty()) {
metadata.setDisplayName(service.getName());
metadata.setDisplayName(serviceProperties.getName());
}

});
}

private void setDefaultServiceIds() {
services.keySet().forEach(serviceKey -> {
final Service service = services.get(serviceKey);
//no service id set
if (service.getId() == null) {
//force id with service name
service.setId(service.getName());
final ServiceProperties serviceProperties = services.get(serviceKey);
//no serviceProperties id set
if (serviceProperties.getId() == null) {
//force id with serviceProperties name
serviceProperties.setId(serviceProperties.getName());
}
});
}

private void setDefaultPlanIds() {
services.keySet().forEach(serviceKey -> {
final Service service = services.get(serviceKey);
if (service.getPlans() != null) {
service.getPlans().keySet().forEach(planKey -> {
final Plan plan = service.getPlans().get(planKey);
final ServiceProperties serviceProperties = services.get(serviceKey);
if (serviceProperties.getPlans() != null) {
serviceProperties.getPlans().keySet().forEach(planKey -> {
final PlanProperties planProperties = serviceProperties.getPlans().get(planKey);
//no plan id set
if (plan.getId() == null) {
//force plan id with service name + plan name
plan.setId(service.getName() + plan.getName());
if (planProperties.getId() == null) {
//force plan id with serviceProperties name + plan name
planProperties.setId(serviceProperties.getName() + planProperties.getName());
}
});
}
Expand All @@ -145,14 +145,14 @@ private void setDefaultPlanIds() {

private void setDefaultPlanDescriptions() {
services.keySet().forEach(serviceKey -> {
final Service service = services.get(serviceKey);
if (service.getPlans() != null) {
service.getPlans().keySet().forEach(planKey -> {
final Plan plan = service.getPlans().get(planKey);
final ServiceProperties serviceProperties = services.get(serviceKey);
if (serviceProperties.getPlans() != null) {
serviceProperties.getPlans().keySet().forEach(planKey -> {
final PlanProperties planProperties = serviceProperties.getPlans().get(planKey);
//no plan id set
if (plan.getDescription() == null) {
if (planProperties.getDescription() == null) {
//force plan description with plan name
plan.setDescription("plan " + plan.getName());
planProperties.setDescription("plan " + planProperties.getName());
}
});
}
Expand All @@ -161,36 +161,36 @@ private void setDefaultPlanDescriptions() {

private void setDefaultPlan() {
services.keySet().forEach(serviceKey -> {
final Service service = services.get(serviceKey);
if (service.getPlans() == null || service.getPlans().isEmpty()) {
Map<String, Plan> plans = new HashMap<>();
Plan plan = new Plan();
plans.put(plan.getName(), plan);
service.setPlans(plans);
final ServiceProperties serviceProperties = services.get(serviceKey);
if (serviceProperties.getPlans() == null || serviceProperties.getPlans().isEmpty()) {
Map<String, PlanProperties> plans = new HashMap<>();
PlanProperties planProperties = new PlanProperties();
plans.put(planProperties.getName(), planProperties);
serviceProperties.setPlans(plans);
}
});
}

public class NoCredentialException extends IllegalStateException {


public NoCredentialException(Plan plan) {
super("No credential has been set for plan " + plan);
public NoCredentialException(PlanProperties planProperties) {
super("No credential has been set for plan " + planProperties);
}
}

public class InvalidSyslogDrainUrlException extends IllegalStateException {


public InvalidSyslogDrainUrlException(Map<String, Service> services) {
public InvalidSyslogDrainUrlException(Map<String, ServiceProperties> services) {
super(String.format("%s includes a syslog_drain_url but \"requires\":[\"syslog_drain\"] is not present", services));
}
}

public class InvalidVolumeMountException extends IllegalStateException {


public InvalidVolumeMountException(Map<String, Service> services) {
public InvalidVolumeMountException(Map<String, ServiceProperties> services) {
super(String.format("%s includes a volume_mount but \"requires\":[\"volume_mount\"] is not present", services));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import java.util.Map;

/**
* Cloud Foundry Service Metadata
* Cloud Foundry ServiceProperties Metadata
* see http://docs.cloudfoundry.org/services/catalog-metadata.html#service-metadata-fields
*/
@Getter
@Setter
@ToString
@EqualsAndHashCode
public class ServiceMetadata {
public class ServiceMetadataProperties {

private String displayName = "";
private String imageUrl = "";
Expand All @@ -25,7 +25,7 @@ public class ServiceMetadata {
private String providerDisplayName = "";
private String longDescription = "";

public ServiceMetadata() {
public ServiceMetadataProperties() {
}

public Map<String, Object> asMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,19 @@
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.boot.json.JsonParser;
import org.springframework.boot.json.JsonParserFactory;
import org.springframework.cloud.servicebroker.model.ServiceDefinitionRequires;

import javax.validation.Valid;
import java.util.*;

/**
* Cloud Foundry Service
* Cloud Foundry ServiceProperties
* http://docs.cloudfoundry.org/services/api.html
*/
@Getter
@Setter
@ToString
@EqualsAndHashCode
public class Service {
public class ServiceProperties {

public static final String NO_NAME_ERROR = "Invalid configuration. No name has been set for service";
public static final String NO_DESCRIPTION_ERROR = "Invalid configuration. No description has been set for service";
Expand All @@ -41,12 +40,12 @@ public class Service {
private List<String> tags;

@Valid
private ServiceMetadata metadata = new ServiceMetadata();
private ServiceMetadataProperties metadata = new ServiceMetadataProperties();

//@NotEmpty(message = NO_PLAN_ERROR)
//@Size(min=1,message = NO_PLAN_ERROR)
@Valid
private Map<String, Plan> plans = new HashMap<>();
private Map<String, PlanProperties> plans = new HashMap<>();

private Map<String, Object> credentials = new HashMap<>();

Expand All @@ -58,8 +57,7 @@ public class Service {
private String syslogDrainUrl;

/**
* A list of permissions that the user would have to give the service, if they provision it. See
* {@link ServiceDefinitionRequires} for supported permissions.
* A list of permissions that the user would have to give the service, if they provision it.
*/
private List<String> requires;

Expand All @@ -75,10 +73,10 @@ public class Service {
@NestedConfigurationProperty
private List<VolumeMountProperties> volumeMounts = new ArrayList<>();

public Service() {
public ServiceProperties() {
}

public Service(String id) {
public ServiceProperties(String id) {
this.id = id;
}

Expand Down
Loading

0 comments on commit 96e8d0f

Please sign in to comment.