Resource project error / <my project> "not found" when trying to get a list of running instances

My goal is to check google orchestrator and api computing engine by first getting a list of active instances. The orchestra project, including the servlet file, is stored in the bank.

I am trying to check the java client of Google Engine Engine. I have a cron job that invokes an orchestra servlet. The purpose of cron is the backend. From which I am trying to get a 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()); } } ... 

I get an error message (I omitted my project name from the answer, I confirmed that I am using the correct project identifier 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 also tried to do this by extracting the access token and making a RESTful call to get a list of instances, and I got the same answer. I confirmed that the built Url was correct by comparing it to a successful request for instances using api explorer.

EDIT: I solved the problem using another message: Finally, I was able to find the solution in the message Error API Compute Engine API with http 404

I needed to add my application engine service account as a member of a team with editing capabilities, which it is not specified by default. Once I did this, the code worked properly. I had to do this through cloud.google.com/console, as if it were done through appengine.google.com, the pending status would be granted to the service account and would not have access.

+6
source share
3 answers

Do you have access to the developer console https://console.developers.google.com ? It seems that the user account @ appspot.gserviceaccount.com does not have access to the computing 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 customer ID

+2
source

I needed to make sure that I had permission. Try this in gcloud auth login terminal

+4
source

Make sure you are in the right project, you can run this command on your vm to make sure you are in the right project: List of gcloud settings

Take a look at this post in Google Groups

+1
source

Source: https://habr.com/ru/post/971665/


All Articles