use of com.woorea.openstack.glance.model.v2.Image in project ovirt-engine by oVirt.
the class OpenStackImageProviderProxy method setCowVirtualSizeAndQcowCompat.
private void setCowVirtualSizeAndQcowCompat(DiskImage diskImage, Image glanceImage) {
// For the qcow2 format we need to download the image header and read the virtual size from there
byte[] imgContent = new byte[72];
ImageDownload downloadImage = getClient().images().download(glanceImage.getId()).execute();
try (InputStream inputStream = downloadImage.getInputStream()) {
int bytesRead = inputStream.read(imgContent, 0, imgContent.length);
if (bytesRead != imgContent.length) {
throw new OpenStackImageException(OpenStackImageException.ErrorType.UNABLE_TO_DOWNLOAD_IMAGE, "Unable to read image header: " + bytesRead);
}
} catch (IOException e) {
throw new OpenStackImageException(OpenStackImageException.ErrorType.UNABLE_TO_DOWNLOAD_IMAGE, "Unable to download image");
}
ByteBuffer b = ByteBuffer.wrap(imgContent);
int qcow2Signature = b.getInt();
int qcow2Version = b.getInt();
QcowCompat qcowCompat = QcowCompat.forQcowHeaderVersion(qcow2Version);
if (qcow2Signature == QCOW2_SIGNATURE && qcowCompat != null && qcowCompat != QcowCompat.Undefined) {
b.position(QCOW2_SIZE_OFFSET);
diskImage.setSize(b.getLong());
diskImage.setQcowCompat(qcowCompat);
} else {
throw new OpenStackImageException(OpenStackImageException.ErrorType.UNRECOGNIZED_IMAGE_FORMAT, "Unable to recognize QCOW2 format");
}
}
use of com.woorea.openstack.glance.model.v2.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.woorea.openstack.glance.model.v2.Image in project hortonmachine by TheHortonMachine.
the class GeopaparazziController method init.
@SuppressWarnings({ "serial" })
private void init() {
_infoArea = new JTextPane();
// _infoArea.setDocument(new SqlDocument());
_infoArea.setContentType("text/html");
_infoArea.setEditable(false);
_infoScroll.setViewportView(_infoArea);
// _infoScroll.setMinimumSize(new Dimension(10, 200));
_chartHolder.setLayout(new BorderLayout());
_loadFolderButton.setIcon(ImageCache.getInstance().getImage(ImageCache.REFRESH));
_loadFolderButton.setText("");
_loadFolderButton.setPreferredSize(preferredButtonSize);
_loadFolderButton.addActionListener(e -> {
final File geopaparazziFolder = new File(_projectsFolderTextfield.getText());
if (!geopaparazziFolder.exists()) {
GuiUtilities.showWarningMessage(this, null, "The projects folder doesn't exist.");
return;
}
File[] projectFiles = GeopaparazziUtilities.getGeopaparazziFiles(geopaparazziFolder);
try {
projectInfos = readProjectInfos(projectFiles);
layoutTree(projectInfos, false);
_filterTextfield.setText("");
} catch (Exception e1) {
Logger.INSTANCE.insertError("", "error", e1);
}
});
_projectsFolderBrowseButton.setPreferredSize(preferredButtonSize);
_projectsFolderBrowseButton.addActionListener(e -> {
File[] openFiles = guiBridge.showOpenDirectoryDialog("Open projects folder", PreferencesHandler.getLastFile());
if (openFiles != null && openFiles.length > 0) {
try {
PreferencesHandler.setLastPath(openFiles[0].getAbsolutePath());
} catch (Exception e1) {
Logger.INSTANCE.insertError("", "ERROR", e1);
}
} else {
return;
}
_projectsFolderTextfield.setText(openFiles[0].getAbsolutePath());
});
String lastSavedPath = prefsMap.get(GuiBridgeHandler.LAST_GP_PROJECTS_PATH);
_projectsFolderTextfield.setText(lastSavedPath);
_filterTextfield.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
String filterText = _filterTextfield.getText().toLowerCase();
final List<ProjectInfo> filtered = new ArrayList<ProjectInfo>();
if (filterText == null) {
filtered.addAll(projectInfos);
} else {
for (ProjectInfo projectInfo : projectInfos) {
if (projectInfo.fileName.toLowerCase().contains(filterText) || projectInfo.metadata.toLowerCase().contains(filterText)) {
filtered.add(projectInfo);
}
}
}
layoutTree(filtered, false);
}
});
addComponentListener(new ComponentListener() {
public void componentShown(ComponentEvent e) {
}
public void componentResized(ComponentEvent e) {
}
public void componentMoved(ComponentEvent e) {
}
public void componentHidden(ComponentEvent e) {
onClose();
}
});
try {
_databaseTreeView.setMinimumSize(new Dimension(300, 200));
addJtreeDragNDrop();
addJtreeContextMenu();
_databaseTree.setRootVisible(false);
_databaseTree.setCellRenderer(new DefaultTreeCellRenderer() {
@Override
public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
if (value instanceof ProjectInfo) {
setIcon(ImageCache.getInstance().getImage(ImageCache.DATABASE));
} else if (value instanceof Image) {
setIcon(ImageCache.getInstance().getImage(ImageCache.DBIMAGE));
} else if (value instanceof GpsLog) {
setIcon(ImageCache.getInstance().getImage(ImageCache.GEOM_LINE));
} else if (value instanceof Note) {
setIcon(ImageCache.getInstance().getImage(ImageCache.NOTE));
}
return this;
}
});
_databaseTree.addTreeSelectionListener(new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent evt) {
TreePath[] paths = evt.getPaths();
currentSelectedProject = null;
currentSelectedImage = null;
currentSelectedNote = null;
currentSelectedGpsLog = null;
_chartHolder.removeAll();
if (paths.length > 0) {
Object selectedItem = paths[0].getLastPathComponent();
if (selectedItem instanceof ProjectInfo) {
currentSelectedProject = (ProjectInfo) selectedItem;
selectProjectInfo(currentSelectedProject);
Logger.INSTANCE.insertDebug("", "Selected project: " + currentSelectedProject.fileName);
}
if (selectedItem instanceof Image) {
currentSelectedImage = (Image) selectedItem;
currentSelectedProject = getProjectForImage(currentSelectedImage);
selectImage(currentSelectedImage);
Logger.INSTANCE.insertDebug("", "Selected image: " + currentSelectedImage.getName() + " of project " + currentSelectedProject.fileName);
}
if (selectedItem instanceof GpsLog) {
currentSelectedGpsLog = (GpsLog) selectedItem;
currentSelectedProject = getProjectForGpsLog(currentSelectedGpsLog);
selectGpsLog(currentSelectedGpsLog);
Logger.INSTANCE.insertDebug("", "Selected gpslog: " + currentSelectedGpsLog.text + " of project " + currentSelectedProject.fileName);
}
if (selectedItem instanceof Note) {
currentSelectedNote = (Note) selectedItem;
currentSelectedProject = getProjectForNote(currentSelectedNote);
selectNote(currentSelectedNote);
Logger.INSTANCE.insertDebug("", "Selected note: " + currentSelectedNote.simpleText + " of project " + currentSelectedProject.fileName);
}
}
}
});
_databaseTree.setVisible(false);
} catch (Exception e1) {
Logger.INSTANCE.insertError("", "Error", e1);
}
layoutTree(null, false);
Component wwjPanelComponent = null;
try {
wwjPanelComponent = NwwPanel.createNwwPanel(true);
} catch (UnsatisfiedLinkError e1) {
// ignore
}
if (wwjPanelComponent instanceof NwwPanel) {
_nwwHolder.setLayout(new BorderLayout());
_nwwHolder.add(wwjPanelComponent, BorderLayout.CENTER);
wwjPanel = (NwwPanel) wwjPanelComponent;
wwjPanel.addOsmLayer();
geopapDataLayer = new RenderableLayer();
wwjPanel.addLayer(geopapDataLayer);
} else {
_nwwHolderFrame.setVisible(false);
_chartHolderFrame.setVisible(false);
setPreferredSize(new Dimension(400, 600));
}
}
use of com.woorea.openstack.glance.model.v2.Image in project hortonmachine by TheHortonMachine.
the class OmsGeopaparazzi4Converter method media2FeatureCollection.
public static SimpleFeatureCollection media2FeatureCollection(IHMConnection connection, File mediaFolderFile, IHMProgressMonitor pm) throws Exception, IOException, FileNotFoundException {
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
try {
GeometryFactory gf = GeometryUtilities.gf();
/*
* create the points shapefile
*/
newCollection = new DefaultFeatureCollection();
SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
b.setName("geopaparazzimediapoints");
b.setCRS(DefaultGeographicCRS.WGS84);
b.add("the_geom", Point.class);
String altimFN = ImageTableFields.COLUMN_ALTIM.getFieldName();
String tsFN = ImageTableFields.COLUMN_TS.getFieldName();
String azimFN = ImageTableFields.COLUMN_AZIM.getFieldName();
String imageNameFN = ImageTableFields.COLUMN_TEXT.getFieldName();
b.add(altimFN, String.class);
b.add(tsFN, String.class);
b.add(azimFN, Double.class);
b.add(imageNameFN, String.class);
SimpleFeatureType featureType = b.buildFeatureType();
List<Image> imagesList = DaoImages.getImagesList(connection);
pm.beginTask("Importing media...", imagesList.size());
for (Image image : imagesList) {
File newImageFile = new File(mediaFolderFile, image.getName());
byte[] imageData = DaoImages.getImageData(connection, image.getImageDataId());
try (OutputStream outStream = new FileOutputStream(newImageFile)) {
outStream.write(imageData);
}
Point point = gf.createPoint(new Coordinate(image.getLon(), image.getLat()));
long ts = image.getTs();
String dateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(ts));
String imageRelativePath = mediaFolderFile.getName() + "/" + image.getName();
Object[] values = new Object[] { point, image.getAltim(), dateTimeString, image.getAzim(), imageRelativePath };
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
builder.addAll(values);
SimpleFeature feature = builder.buildFeature(null);
newCollection.add(feature);
pm.worked(1);
}
} finally {
pm.done();
}
return newCollection;
}
use of com.woorea.openstack.glance.model.v2.Image in project hortonmachine by TheHortonMachine.
the class OmsGeopaparazzi4Converter method media2IdBasedFeatureCollection.
public static SimpleFeatureCollection media2IdBasedFeatureCollection(IHMConnection connection, IHMProgressMonitor pm) throws Exception, IOException, FileNotFoundException {
try {
GeometryFactory gf = GeometryUtilities.gf();
/*
* create the points fc
*/
DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
SimpleFeatureType featureType = GeopaparazziUtilities.getMediaFeaturetype();
List<Image> imagesList = DaoImages.getImagesList(connection);
pm.beginTask("Importing media...", imagesList.size());
for (Image image : imagesList) {
Point point = gf.createPoint(new Coordinate(image.getLon(), image.getLat()));
long ts = image.getTs();
String dateTimeString = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(ts));
Object[] values = new Object[] { point, image.getAltim(), dateTimeString, image.getAzim(), image.getImageDataId() };
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);
builder.addAll(values);
SimpleFeature feature = builder.buildFeature(null);
newCollection.add(feature);
pm.worked(1);
}
return newCollection;
} finally {
pm.done();
}
}
Aggregations