/*
 * Copyright (c) 2015 Google, Inc.
 *
 * Licensed 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 com.cloudera.director.google;

import com.cloudera.director.google.compute.GoogleComputeProvider;
import com.cloudera.director.google.internal.GoogleCredentials;
import com.cloudera.director.spi.v1.model.ConfigurationProperty;
import com.cloudera.director.spi.v1.model.Configured;
import com.cloudera.director.spi.v1.provider.CloudProvider;
import com.cloudera.director.spi.v1.provider.CloudProviderMetadata;
import com.cloudera.director.spi.v1.provider.ResourceProvider;
import com.cloudera.director.spi.v1.provider.ResourceProviderMetadata;
import com.cloudera.director.spi.v1.provider.util.SimpleCloudProviderMetadataBuilder;

import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;

public class GoogleCloudProvider implements CloudProvider {

  public static final String ID = "google";

  private static final List<ResourceProviderMetadata> RESOURCE_PROVIDER_METADATA =
      Collections.singletonList(GoogleComputeProvider.METADATA);

  private GoogleCredentials credentials;

  protected static final CloudProviderMetadata METADATA = new SimpleCloudProviderMetadataBuilder()
      .id(ID)
      .name("Google Cloud Platform (GCP)")
      .description("A provider implementation that provisions virtual resources on Google Cloud Platform.")
      .configurationProperties(Collections.<ConfigurationProperty>emptyList())
      .credentialsProviderMetadata(GoogleCredentialsProvider.METADATA)
      .resourceProviderMetadata(RESOURCE_PROVIDER_METADATA)
      .build();

  public GoogleCloudProvider(GoogleCredentials credentials) {
    this.credentials = credentials;
  }

  @Override
  public CloudProviderMetadata getMetadata() {
    return METADATA;
  }

  @Override
  public ResourceProvider createResourceProvider(String resourceProviderId, Configured configuration) {

    if (GoogleComputeProvider.METADATA.getId().equals(resourceProviderId)) {
      return new GoogleComputeProvider(configuration, credentials);
    }

    throw new NoSuchElementException("Invalid provider id: " + resourceProviderId);
  }
}

/*
 * Copyright (c) 2015 Google, Inc.
 *
 * Licensed 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 com.cloudera.director.google;

import com.cloudera.director.google.compute.GoogleComputeProvider;
import com.cloudera.director.google.internal.GoogleCredentials;
import com.cloudera.director.spi.v1.model.ConfigurationProperty;
import com.cloudera.director.spi.v1.model.Configured;
import com.cloudera.director.spi.v1.provider.CloudProvider;
import com.cloudera.director.spi.v1.provider.CloudProviderMetadata;
import com.cloudera.director.spi.v1.provider.ResourceProvider;
import com.cloudera.director.spi.v1.provider.ResourceProviderMetadata;
import com.cloudera.director.spi.v1.provider.util.SimpleCloudProviderMetadataBuilder;

import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;

public class GoogleCloudProvider implements CloudProvider {

  public static final String ID = "google";

  private static final List<ResourceProviderMetadata> RESOURCE_PROVIDER_METADATA =
      Collections.singletonList(GoogleComputeProvider.METADATA);

  private GoogleCredentials credentials;

  protected static final CloudProviderMetadata METADATA = new SimpleCloudProviderMetadataBuilder()
      .id(ID)
      .name("Google Cloud Platform")
      .description("A provider implementation that provisions virtual resources on Google Cloud Platform.")
      .configurationProperties(Collections.<ConfigurationProperty>emptyList())
      .credentialsProviderMetadata(GoogleCredentialsProvider.METADATA)
      .resourceProviderMetadata(RESOURCE_PROVIDER_METADATA)
      .build();

  public GoogleCloudProvider(GoogleCredentials credentials) {
    this.credentials = credentials;
  }

  @Override
  public CloudProviderMetadata getMetadata() {
    return METADATA;
  }

  @Override
  public ResourceProvider createResourceProvider(String resourceProviderId, Configured configuration) {

    if (GoogleComputeProvider.METADATA.getId().equals(resourceProviderId)) {
      return new GoogleComputeProvider(configuration, credentials);
    }

    throw new NoSuchElementException("Invalid provider id: " + resourceProviderId);
  }
}

Remove (GCP) from CloudProviderMetadata.