Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The resource 'projects/<my project>' was not found" error when trying to get list of running instances

My goal is to test out google's orchestrator and the compute engine api by first retrieving a list of active instances. The orchestrator project including the servlet file is stored in a jar.

I'm trying to test out the java google compute engine client api. I have a cron job which calls on the orchestrator servlet. The target for the cron is a backend. From which I try to get the list of instances:

...
AppIdentityCredential credential = getCredential(computeScope);

String appName = ConfigProperties.getInstance().getGceConfigProperties().get("projectId");

try {
    httpTransport = GoogleNetHttpTransport.newTrustedTransport();

    final Compute compute = new Compute.Builder(
        httpTransport, JSON_FACTORY, credential).setApplicationName(appName)
        .build();
    logger.info("================== Listing Compute Engine Instances ==================");

    Compute.Instances.List instances = compute.instances().list(projectId, zone);
    InstanceList list = instances.execute();

    if (list.getItems() == null) {
        logger.info("No instances found. Sign in to the Google APIs Console and create "
            + "an instance at: code.google.com/apis/console");
    } else {
        for (Instance instance : list.getItems()) {
            logger.info(instance.toPrettyString());
        }
    }
...

There error response I get is(I omitted my project name from the response, I confirmed that I'm using the correct project id in my code):

com.google.cloud.solutions.sampleapps.orchestration.orchestrator.server.GceClientApiUtils      
getInstances: com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 OK
{
  "code" : 404,
  "errors" : [ {
    "domain" : "global",
    "message" : "The resource 'projects/<project-name-here>' was not found",
    "reason" : "notFound"
  } ],
  "message" : "The resource 'projects/<project-name_here>' was not found"
}

I've also attempted this by retrieving an access token and making a RESTful call to get the list of instances and i received the exact same response. I confirmed the Url constructed was correct by comparing it against a successful query of the instances using the api explorer.

EDIT: I determined the solution to the issue with help of another post: I was finally able to find the solution in the post Compute Engine API call fails with http 404

I needed to add my app engine service account as a team member with edit capabilities, which it does not have by default. Once I did this, the code worked as expected. I had to do this through cloud.google.com/console, as if done through appengine.google.com, a pending status will be given to the service account and will not have access.

like image 248
jKimo Avatar asked Jul 02 '14 18:07

jKimo


2 Answers

For me i had to make sure i had authorization. Try this in the terminal gcloud auth login

like image 137
superuserdo Avatar answered Nov 18 '22 06:11

superuserdo


Do you have access to the developers console https://console.developers.google.com? It seems that the user account @appspot.gserviceaccount.com has not access to compute engine. In my case I see @developer.gserviceaccount.com.

If you don't have one, visit https://developers.google.com/console/help/new/#generatingoauth2 to create a new Client ID

like image 28
Marilu Avatar answered Nov 18 '22 05:11

Marilu