getImageId do no need to invoke the real openstack API #881

Open
whaon opened this Issue Nov 7, 2016 · 2 comments

Projects

None yet

2 participants

@whaon
Contributor
whaon commented Nov 7, 2016 edited
@JsonIgnore
	@Override
	public String getImageId() {
		Image image = getImage();
		return (image != null) ? image.getId() : null;
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public Image getImage() {
		if (image instanceof LinkedHashMap) {
			LinkedHashMap map = (LinkedHashMap) image;
			String imageId = (String) map.get("id");
			if (imageId == null || imageId.isEmpty()) {
				return null;
			}
			NovaImage novaImage = (NovaImage) Apis.getComputeServices().images().get(imageId);
			return novaImage;
		}
		return null;
	}

when I invoke the method getImageId(),os4j will always invoke the real openstack API,and it will cause a long time,so we can make it as the below:

       public String getImageId() {
		
		if(image instanceof Map) {
			Map<String, String> map = (Map<String, String>) image;
			return map.get("id");
		}
		return getImage().getId();
	}

when we definitely need a Image Object,then we can invoke the getImage() method,or we have another choice:use the id to invoke the other service

@auhlig auhlig added the enhancement label Nov 7, 2016
@auhlig
Member
auhlig commented Nov 8, 2016

Hey @whaon,
You're talking of the getImageId()-method in NovaServer ,right?

How do we get the image id without getting the image object first? Maybe it gets clearer in the PR. Please add a test.

@whaon
Contributor
whaon commented Nov 8, 2016

Hey @auhlig ,
sorry for not making it clear.
I'm talking of the getImageId()-method in NovaServer.
the field of NovaServer is like below:

public Object image;

and the response data of API /servers/detail is like:

"image": {
                "id": "70a599e0-31e7-49b7-b260-868f441e862b",
                "links": [
                    {
                        "href": "http://openstack.example.com/6f70656e737461636b20342065766572/images/70a599e0-31e7-49b7-b260-868f441e862b",
                        "rel": "bookmark"
                    }
                ]
            },

consider the current method getImage(),the field image is treated as a LinkedHashMap,and can get the id from the map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment