use of com.google.cloud.compute.v1.Image in project java-docs-samples by GoogleCloudPlatform.
the class SnippetsIT method createImage.
private static Image createImage(Disk srcDisk) throws IOException, InterruptedException, ExecutionException {
try (ImagesClient imagesClient = ImagesClient.create()) {
Image image = Image.newBuilder().setName("test-img-" + UUID.randomUUID()).setSourceDisk(srcDisk.getSelfLink()).build();
OperationFuture<Operation, Operation> operation = imagesClient.insertAsync(PROJECT_ID, image);
operation.get();
return imagesClient.get(PROJECT_ID, image.getName());
}
}
use of com.google.cloud.compute.v1.Image in project ovirt-engine by oVirt.
the class OpenStackImageProviderProxy method getAllImagesAsRepoImages.
public List<RepoImage> getAllImagesAsRepoImages(Integer listSize, Integer totalListSize) {
ArrayList<RepoImage> repoImages = new ArrayList<>();
long currentTime = System.currentTimeMillis();
Images images = null;
do {
OpenStackRequest<Images> listRequest = getClient().images().list(true).queryParam("limit", listSize).queryParam("sort_key", "name").queryParam("sort_dir", "asc");
if (images != null) {
listRequest.queryParam("marker", images.getList().get(images.getList().size() - 1).getId());
}
images = listRequest.execute();
for (Image glanceImage : images) {
RepoImage repoImage = imageToRepoImage(glanceImage);
repoImage.setLastRefreshed(currentTime);
repoImages.add(repoImage);
}
} while (images.getList().size() >= listSize && totalListSize != null && repoImages.size() < totalListSize);
return repoImages;
}
use of com.google.cloud.compute.v1.Image in project ovirt-engine by oVirt.
the class OpenStackImageProviderProxy method createImageFromDiskImage.
public String createImageFromDiskImage(DiskImage diskImage) {
Image glanceImage = new Image();
glanceImage.setName(diskImage.getDiskAlias());
if (diskImage.getVolumeFormat() == VolumeFormat.RAW) {
glanceImage.setDiskFormat(GlanceImageFormat.RAW.getValue());
} else if (diskImage.getVolumeFormat() == VolumeFormat.COW) {
glanceImage.setDiskFormat(GlanceImageFormat.COW.getValue());
} else {
throw new OpenStackImageException(OpenStackImageException.ErrorType.UNSUPPORTED_DISK_FORMAT, "Unknown disk format: " + diskImage.getVolumeFormat());
}
glanceImage.setContainerFormat(GlanceImageContainer.BARE.getValue());
Image retGlanceImage = getClient().images().create(glanceImage).execute();
return retGlanceImage.getId();
}
use of com.google.cloud.compute.v1.Image in project java-automl by googleapis.
the class PredictionApi method predict.
// [START automl_vision_predict]
/**
* Demonstrates using the AutoML client to predict an image.
*
* @param projectId the Id of the project.
* @param computeRegion the Region name.
* @param modelId the Id of the model which will be used for text classification.
* @param filePath the Local text file path of the content to be classified.
* @param scoreThreshold the Confidence score. Only classifications with confidence score above
* scoreThreshold are displayed.
*/
static void predict(String projectId, String computeRegion, String modelId, String filePath, String scoreThreshold) throws IOException {
// Instantiate client for prediction service.
try (PredictionServiceClient predictionClient = PredictionServiceClient.create()) {
// Get the full path of the model.
ModelName name = ModelName.of(projectId, computeRegion, modelId);
// Read the image and assign to payload.
ByteString content = ByteString.copyFrom(Files.readAllBytes(Paths.get(filePath)));
Image image = Image.newBuilder().setImageBytes(content).build();
ExamplePayload examplePayload = ExamplePayload.newBuilder().setImage(image).build();
// Additional parameters that can be provided for prediction e.g. Score Threshold
Map<String, String> params = new HashMap<>();
if (scoreThreshold != null) {
params.put("score_threshold", scoreThreshold);
}
// Perform the AutoML Prediction request
PredictResponse response = predictionClient.predict(name, examplePayload, params);
System.out.println("Prediction results:");
for (AnnotationPayload annotationPayload : response.getPayloadList()) {
System.out.println("Predicted class name :" + annotationPayload.getDisplayName());
System.out.println("Predicted class score :" + annotationPayload.getClassification().getScore());
}
}
}
use of com.google.cloud.compute.v1.Image in project openj9 by eclipse-openj9.
the class XMLIndexReader method setJ9DumpData.
public void setJ9DumpData(long environ, String osType, String osSubType, String cpuType, int cpuCount, long bytesMem, int pointerSize, Image[] imageRef, ImageAddressSpace[] addressSpaceRef, ImageProcess[] processRef) {
Builder builder = null;
if (_stream == null) {
// extract directly from the file
builder = new Builder(_coreFile, _reader, environ, _fileResolvingAgent);
} else {
// extract using the data stream
builder = new Builder(_coreFile, _stream, environ, _fileResolvingAgent);
}
_coreFile.extract(builder);
// Jazz 4961 : chamlain : NumberFormatException opening corrupt dump
if (cpuType == null)
cpuType = builder.getCPUType();
String cpuSubType = builder.getCPUSubType();
if (osType == null)
osType = builder.getOSType();
long creationTime = builder.getCreationTime();
_coreImage = new Image(osType, osSubType, cpuType, cpuSubType, cpuCount, bytesMem, creationTime);
ImageAddressSpace addressSpace = (ImageAddressSpace) builder.getAddressSpaces().next();
ImageProcess process = (ImageProcess) addressSpace.getCurrentProcess();
// If not sure, use the first address space/process pair found
for (Iterator it = builder.getAddressSpaces(); it.hasNext(); ) {
ImageAddressSpace addressSpace1 = (ImageAddressSpace) it.next();
final boolean vb = false;
if (vb)
System.out.println("address space " + addressSpace1);
_coreImage.addAddressSpace(addressSpace1);
for (Iterator it2 = addressSpace1.getProcesses(); it2.hasNext(); ) {
ImageProcess process1 = (ImageProcess) it2.next();
if (vb)
try {
System.out.println("process " + process1.getID());
} catch (DataUnavailable e) {
} catch (CorruptDataException e) {
}
if (process == null || isProcessForEnvironment(environ, addressSpace1, process1)) {
addressSpace = addressSpace1;
process = process1;
if (vb)
System.out.println("default process for Runtime");
}
}
}
if (null != process) {
// z/OS can have 64-bit or 31-bit processes, Java only reports 64-bit or 32-bit.
if (process.getPointerSize() != pointerSize && !(process.getPointerSize() == 31 && pointerSize == 32)) {
System.out.println("XML and core file pointer sizes differ " + process.getPointerSize() + "!=" + pointerSize);
}
} else {
throw new IllegalStateException("No process found in the dump.");
}
imageRef[0] = _coreImage;
addressSpaceRef[0] = addressSpace;
processRef[0] = process;
}
Aggregations