org.cloudfoundry.community.servicebroker.model.ServiceInstance Java Examples

The following examples show how to use org.cloudfoundry.community.servicebroker.model.ServiceInstance. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PostgreSQLServiceInstanceService.java    From postgresql-cf-service-broker with Apache License 2.0 6 votes vote down vote up
@Override
public ServiceInstance createServiceInstance(CreateServiceInstanceRequest createServiceInstanceRequest)
        throws ServiceInstanceExistsException, ServiceBrokerException {
    String serviceInstanceId = createServiceInstanceRequest.getServiceInstanceId();
    String serviceId = createServiceInstanceRequest.getServiceDefinitionId();
    String planId = createServiceInstanceRequest.getPlanId();
    String organizationGuid = createServiceInstanceRequest.getOrganizationGuid();
    String spaceGuid = createServiceInstanceRequest.getSpaceGuid();
    try {
        db.createDatabaseForInstance(serviceInstanceId, serviceId, planId, organizationGuid, spaceGuid);
        role.createRoleForInstance(serviceInstanceId);
    } catch (SQLException e) {
        logger.error("Error while creating service instance '" + serviceInstanceId + "'", e);
        throw new ServiceBrokerException(e.getMessage());
    }
    return new ServiceInstance(createServiceInstanceRequest);
}
 
Example #2
Source File: Database.java    From postgresql-cf-service-broker with Apache License 2.0 6 votes vote down vote up
public ServiceInstance findServiceInstance(String instanceId) throws SQLException {
    Utils.checkValidUUID(instanceId);

    Map<Integer, String> parameterMap = new HashMap<Integer, String>();
    parameterMap.put(1, instanceId);

    Map<String, String> result = PostgreSQLDatabase.executePreparedSelect("SELECT * FROM service WHERE serviceinstanceid = ?", parameterMap);

    String serviceDefinitionId = result.get("servicedefinitionid");
    String organizationGuid = result.get("organizationguid");
    String planId = result.get("planid");
    String spaceGuid = result.get("spaceguid");

    CreateServiceInstanceRequest wrapper = new CreateServiceInstanceRequest(serviceDefinitionId, planId, organizationGuid, spaceGuid).withServiceInstanceId(instanceId);
    return new ServiceInstance(wrapper);
}
 
Example #3
Source File: S3.java    From s3-cf-service-broker with Apache License 2.0 6 votes vote down vote up
private ServiceInstance createServiceInstance(BucketTaggingConfiguration taggingConfiguration) {
    // While the Java API has multiple TagSets, it would appear from
    // http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketPUTtagging.html
    // that only one TagSet is supported.
    TagSet tagSet = taggingConfiguration.getTagSet();
    String serviceInstanceId = tagSet.getTag("serviceInstanceId");
    if (serviceInstanceId == null) {
        // could occur if someone used this broker AWS ID to a bucket
        // outside of the broker process
        return null;
    }
    String serviceDefinitionId = tagSet.getTag("serviceDefinitionId");
    String planId = tagSet.getTag("planId");
    String organizationGuid = tagSet.getTag("organizationGuid");
    String spaceGuid = tagSet.getTag("spaceGuid");
    ServiceInstance serviceInstance = new ServiceInstance(serviceInstanceId, serviceDefinitionId, planId,
            organizationGuid, spaceGuid, null);
    return serviceInstance;
}
 
Example #4
Source File: BasicPlan.java    From s3-cf-service-broker with Apache License 2.0 6 votes vote down vote up
public ServiceInstanceBinding createServiceInstanceBinding(String bindingId, ServiceInstance serviceInstance,
                                                           String serviceId, String planId, String appGuid) {
    User user = iam.createUserForBinding(bindingId);
    AccessKey accessKey = iam.createAccessKey(user);
    // TODO create password and add to credentials
    iam.addUserToGroup(user, iam.getGroupNameForInstance(serviceInstance.getId()));
    String bucketName = s3.getBucketNameForInstance(serviceInstance.getId());
    Map<String, Object> credentials = new HashMap<String, Object>();
    credentials.put("bucket", bucketName);
    credentials.put("username", user.getUserName());
    credentials.put("access_key_id", accessKey.getAccessKeyId());
    credentials.put("secret_access_key", accessKey.getSecretAccessKey());
    credentials.put("host", AMAZON_S3_HOST);
    credentials.put("uri", this.generateUri(accessKey.getAccessKeyId(), accessKey.getSecretAccessKey(), bucketName));
    return new ServiceInstanceBinding(bindingId, serviceInstance.getId(), credentials, null, appGuid);
}
 
Example #5
Source File: ServiceInstanceFixture.java    From spring-boot-cf-service-broker with Apache License 2.0 5 votes vote down vote up
public static ServiceInstance getServiceInstanceTwo() {
	return new ServiceInstance(new CreateServiceInstanceRequest(
			"service-two-id", 
			"plan-two-id", 
			DataFixture.getOrgOneGuid(), 
			DataFixture.getSpaceOneGuid(),
			false,
			ParametersFixture.getParameters())
		.withServiceInstanceId("service-instnce-two-id"))
		.withDashboardUrl("dashboard_url");

}
 
Example #6
Source File: S3.java    From s3-cf-service-broker with Apache License 2.0 5 votes vote down vote up
public List<ServiceInstance> getAllServiceInstances() {
    List<ServiceInstance> serviceInstances = Lists.newArrayList();
    for (Bucket bucket : s3.listBuckets()) {
        BucketTaggingConfiguration taggingConfiguration = s3.getBucketTaggingConfiguration(bucket.getName());
        ServiceInstance serviceInstance = createServiceInstance(taggingConfiguration);
        serviceInstances.add(serviceInstance);
    }
    return serviceInstances;
}
 
Example #7
Source File: S3.java    From s3-cf-service-broker with Apache License 2.0 5 votes vote down vote up
public ServiceInstance findServiceInstance(String instanceId) {
    String bucketName = getBucketNameForInstance(instanceId);
    if (s3.doesBucketExist(bucketName)) {
        BucketTaggingConfiguration taggingConfiguration = s3.getBucketTaggingConfiguration(bucketName);
        return createServiceInstance(taggingConfiguration);
    }
    return null;
}
 
Example #8
Source File: BasicPlan.java    From s3-cf-service-broker with Apache License 2.0 5 votes vote down vote up
public ServiceInstance createServiceInstance(ServiceDefinition service, String serviceInstanceId, String planId,
                                             String organizationGuid, String spaceGuid) {
    Bucket bucket = s3.createBucketForInstance(serviceInstanceId, service, planId, organizationGuid, spaceGuid);
    iam.createGroupForInstance(serviceInstanceId, bucket.getName());
    iam.applyGroupPolicyForInstance(serviceInstanceId, bucket.getName());
    return new ServiceInstance(serviceInstanceId, service.getId(), planId, organizationGuid, spaceGuid, null);
}
 
Example #9
Source File: BasicPlan.java    From s3-cf-service-broker with Apache License 2.0 5 votes vote down vote up
public ServiceInstance deleteServiceInstance(String id) {
    ServiceInstance instance = s3.findServiceInstance(id);
    // TODO we need to make these deletes idempotent so we can handle retries on error
    iam.deleteGroupPolicyForInstance(id);
    iam.deleteGroupForInstance(id);
    s3.emptyBucket(id);
    s3.deleteBucket(id);
    return instance;
}
 
Example #10
Source File: ServiceInstanceFixture.java    From spring-boot-cf-service-broker with Apache License 2.0 5 votes vote down vote up
public static ServiceInstance getServiceInstance() {
	return new ServiceInstance(new CreateServiceInstanceRequest(
			"service-one-id", 
			"plan-one-id", 
			DataFixture.getOrgOneGuid(), 
			DataFixture.getSpaceOneGuid(), 
			false,
			ParametersFixture.getParameters())
		.withServiceInstanceId("service-instnce-one-id"))
		.withDashboardUrl("dashboard_url");
			
}
 
Example #11
Source File: BasicPlan.java    From s3-cf-service-broker with Apache License 2.0 5 votes vote down vote up
public ServiceInstanceBinding deleteServiceInstanceBinding(String bindingId, ServiceInstance serviceInstance,
                                                           String serviceId, String planId) throws ServiceBrokerException {
    // TODO make operations idempotent so we can handle retries on error
    iam.removeUserFromGroupForInstance(bindingId, serviceInstance.getId());
    iam.deleteUserAccessKeysForBinding(bindingId);
    iam.deleteUserForBinding(bindingId);
    return new ServiceInstanceBinding(bindingId, serviceInstance.getId(), null, null, null);
}
 
Example #12
Source File: PostgreSQLServiceInstanceService.java    From postgresql-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceInstance getServiceInstance(String id) {
    try {
        return db.findServiceInstance(id);
    } catch (SQLException e) {
        logger.error("Error while finding service instance '" + id + "'", e);
        return null;
    }
}
 
Example #13
Source File: PostgreSQLServiceInstanceService.java    From postgresql-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public ServiceInstance deleteServiceInstance(DeleteServiceInstanceRequest deleteServiceInstanceRequest)
        throws ServiceBrokerException {
    String serviceInstanceId = deleteServiceInstanceRequest.getServiceInstanceId();
    ServiceInstance instance = getServiceInstance(serviceInstanceId);

    try {
        db.deleteDatabase(serviceInstanceId);
        role.deleteRole(serviceInstanceId);
    } catch (SQLException e) {
        logger.error("Error while deleting service instance '" + serviceInstanceId + "'", e);
        throw new ServiceBrokerException(e.getMessage());
    }
    return instance;
}
 
Example #14
Source File: S3ServiceInstanceService.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public ServiceInstance getServiceInstance(String id) {
    return plan.getServiceInstance(id);
}
 
Example #15
Source File: Plan.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
ServiceInstanceBinding deleteServiceInstanceBinding(String bindingId, ServiceInstance serviceInstance,
String serviceId, String planId) throws ServiceBrokerException;
 
Example #16
Source File: Plan.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
ServiceInstanceBinding createServiceInstanceBinding(String bindingId, ServiceInstance serviceInstance,
String serviceId, String planId, String appGuid);
 
Example #17
Source File: Plan.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
ServiceInstance createServiceInstance(ServiceDefinition service, String serviceInstanceId, String planId,
String organizationGuid, String spaceGuid);
 
Example #18
Source File: BasicPlan.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
public List<ServiceInstance> getAllServiceInstances() {
    return s3.getAllServiceInstances();
}
 
Example #19
Source File: BasicPlan.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
public ServiceInstance getServiceInstance(String id) {
    return s3.findServiceInstance(id);
}
 
Example #20
Source File: S3ServiceInstanceService.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public List<ServiceInstance> getAllServiceInstances() {
    return plan.getAllServiceInstances();
}
 
Example #21
Source File: S3ServiceInstanceService.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public ServiceInstance deleteServiceInstance(String id, String serviceId, String planId)
        throws ServiceBrokerException {
    return plan.deleteServiceInstance(id);
}
 
Example #22
Source File: S3ServiceInstanceService.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public ServiceInstance createServiceInstance(ServiceDefinition service, String serviceInstanceId, String planId,
        String organizationGuid, String spaceGuid) throws ServiceInstanceExistsException, ServiceBrokerException {
    return plan.createServiceInstance(service, serviceInstanceId, planId, organizationGuid, spaceGuid);
}
 
Example #23
Source File: S3ServiceInstanceBindingService.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public ServiceInstanceBinding deleteServiceInstanceBinding(String bindingId, ServiceInstance serviceInstance,
        String serviceId, String planId) throws ServiceBrokerException {
    return plan.deleteServiceInstanceBinding(bindingId, serviceInstance, serviceId, planId);
}
 
Example #24
Source File: S3ServiceInstanceBindingService.java    From s3-cf-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public ServiceInstanceBinding createServiceInstanceBinding(String bindingId, ServiceInstance serviceInstance,
        String serviceId, String planId, String appGuid) throws ServiceInstanceBindingExistsException,
        ServiceBrokerException {
    return plan.createServiceInstanceBinding(bindingId, serviceInstance, serviceId, planId, appGuid);
}
 
Example #25
Source File: ServiceInstanceFixture.java    From spring-boot-cf-service-broker with Apache License 2.0 4 votes vote down vote up
public static ServiceInstance getAsyncServiceInstance() {
	return new ServiceInstance(
			new CreateServiceInstanceRequest(null, null, null, null, true, null))
			.withDashboardUrl(null);
}
 
Example #26
Source File: ServiceInstanceFixture.java    From spring-boot-cf-service-broker with Apache License 2.0 4 votes vote down vote up
public static List<ServiceInstance> getAllServiceInstances() {
	List<ServiceInstance> instances = new ArrayList<ServiceInstance>();
	instances.add(getServiceInstance());
	instances.add(getServiceInstanceTwo());
	return instances;
}
 
Example #27
Source File: ServiceInstanceExistsException.java    From spring-boot-cf-service-broker with Apache License 2.0 4 votes vote down vote up
public ServiceInstanceExistsException(ServiceInstance instance) {
	super("ServiceInstance with the given ID already exists: " +
			"ServiceInstance.id = " + instance.getServiceInstanceId() +
			", Service.id = " + instance.getServiceDefinitionId());
}
 
Example #28
Source File: PostgreSQLServiceInstanceService.java    From postgresql-cf-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public ServiceInstance updateServiceInstance(UpdateServiceInstanceRequest updateServiceInstanceRequest)
        throws ServiceInstanceUpdateNotSupportedException, ServiceBrokerException, ServiceInstanceDoesNotExistException {
    throw new IllegalStateException("Not implemented");
}
 
Example #29
Source File: Database.java    From postgresql-cf-service-broker with Apache License 2.0 4 votes vote down vote up
public List<ServiceInstance> getAllServiceInstances() {
    return Collections.emptyList();
}
 
Example #30
Source File: Plan.java    From s3-cf-service-broker with Apache License 2.0 votes vote down vote up
ServiceInstance deleteServiceInstance(String id);