Search in sources :

Example 6 with RevTag

use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.

the class HttpRemoteRepo method fetchMoreData.

/**
     * Retrieve objects from the remote repository, and update have/want lists accordingly.
     * Specifically, any retrieved commits are removed from the want list and added to the have
     * list, and any parents of those commits are removed from the have list (it only represents the
     * most recent common commits.) Retrieved objects are added to the local repository, and the
     * want/have lists are updated in-place.
     * 
     * @param want a list of ObjectIds that need to be fetched
     * @param have a list of ObjectIds that are in common with the remote repository
     * @param progress
     */
private void fetchMoreData(final List<ObjectId> want, final Set<ObjectId> have, final ProgressListener progress) {
    final JsonObject message = createFetchMessage(want, have);
    final URL resourceURL;
    try {
        resourceURL = new URL(repositoryURL.toString() + "/repo/batchobjects");
    } catch (MalformedURLException e) {
        throw Throwables.propagate(e);
    }
    final HttpURLConnection connection;
    try {
        final Gson gson = new Gson();
        OutputStream out;
        final Writer writer;
        connection = (HttpURLConnection) resourceURL.openConnection();
        connection.setDoOutput(true);
        connection.setDoInput(true);
        connection.addRequestProperty("Accept-Encoding", "gzip");
        out = connection.getOutputStream();
        writer = new OutputStreamWriter(out);
        gson.toJson(message, writer);
        writer.flush();
        out.flush();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
    final HttpUtils.ReportingInputStream in = HttpUtils.getResponseStream(connection);
    BinaryPackedObjects unpacker = new BinaryPackedObjects(localRepository.objectDatabase());
    BinaryPackedObjects.Callback callback = new BinaryPackedObjects.Callback() {

        @Override
        public void callback(Supplier<RevObject> supplier) {
            RevObject object = supplier.get();
            progress.setProgress(progress.getProgress() + 1);
            if (object instanceof RevCommit) {
                RevCommit commit = (RevCommit) object;
                want.remove(commit.getId());
                have.removeAll(commit.getParentIds());
                have.add(commit.getId());
            } else if (object instanceof RevTag) {
                RevTag tag = (RevTag) object;
                want.remove(tag.getId());
                have.remove(tag.getCommitId());
                have.add(tag.getId());
            }
        }
    };
    Stopwatch sw = Stopwatch.createStarted();
    IngestResults ingestResults = unpacker.ingest(in, callback);
    sw.stop();
    String msg = String.format("Processed %,d objects. Inserted: %,d. Existing: %,d. Time: %s. Compressed size: %,d bytes. Uncompressed size: %,d bytes.", ingestResults.total(), ingestResults.getInserted(), ingestResults.getExisting(), sw, in.compressedSize(), in.unCompressedSize());
    LOGGER.info(msg);
    progress.setDescription(msg);
}
Also used : MalformedURLException(java.net.MalformedURLException) RevTag(org.locationtech.geogig.api.RevTag) RevObject(org.locationtech.geogig.api.RevObject) ReportingOutputStream(org.locationtech.geogig.remote.HttpUtils.ReportingOutputStream) OutputStream(java.io.OutputStream) FilterOutputStream(java.io.FilterOutputStream) Stopwatch(com.google.common.base.Stopwatch) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) IOException(java.io.IOException) IngestResults(org.locationtech.geogig.remote.BinaryPackedObjects.IngestResults) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) OutputStreamWriter(java.io.OutputStreamWriter) Supplier(com.google.common.base.Supplier) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 7 with RevTag

use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.

the class TagCreateOp method _call.

/**
     * Executes the tag creation operation.
     * 
     * @return the created tag
     * 
     */
@Override
protected RevTag _call() throws RuntimeException {
    checkState(name != null, "tag name was not provided");
    final String tagRefPath = Ref.TAGS_PREFIX + name;
    checkArgument(!command(RefParse.class).setName(tagRefPath).call().isPresent(), "A tag named '" + name + "' already exists.");
    if (commitId == null) {
        final Optional<Ref> currHead = command(RefParse.class).setName(Ref.HEAD).call();
        Preconditions.checkState(currHead.isPresent(), "Repository has no HEAD, can't create tag");
        commitId = currHead.get().getObjectId();
    }
    RevPerson tagger = resolveTagger();
    message = message == null ? "" : message;
    RevTag tag = new RevTagImpl(ObjectId.NULL, name, commitId, message, tagger);
    ObjectId id = command(HashObject.class).setObject(tag).call();
    tag = new RevTagImpl(id, name, commitId, message, tagger);
    objectDatabase().put(tag);
    Optional<Ref> branchRef = command(UpdateRef.class).setName(tagRefPath).setNewValue(tag.getId()).call();
    checkState(branchRef.isPresent());
    return tag;
}
Also used : Ref(org.locationtech.geogig.api.Ref) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef) RevPerson(org.locationtech.geogig.api.RevPerson) RevTag(org.locationtech.geogig.api.RevTag) ObjectId(org.locationtech.geogig.api.ObjectId) RevTagImpl(org.locationtech.geogig.api.RevTagImpl) RefParse(org.locationtech.geogig.api.plumbing.RefParse) UpdateRef(org.locationtech.geogig.api.plumbing.UpdateRef)

Example 8 with RevTag

use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.

the class CatWebOp method run.

/**
     * Runs the command and builds the appropriate response
     * 
     * @param context - the context to use for this command
     * 
     * @throws CommandSpecException
     */
@Override
public void run(CommandContext context) {
    Preconditions.checkArgument(object != null && !object.equals(ObjectId.NULL));
    final Context geogig = this.getCommandLocator(context);
    Preconditions.checkState(geogig.stagingDatabase().exists(object));
    final RevObject revObject = geogig.stagingDatabase().get(object);
    switch(revObject.getType()) {
        case COMMIT:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeCommit((RevCommit) revObject, "commit", null, null, null);
                    out.finish();
                }
            });
            break;
        case TREE:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeTree((RevTree) revObject, "tree");
                    out.finish();
                }
            });
            break;
        case FEATURE:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeFeature((RevFeature) revObject, "feature");
                    out.finish();
                }
            });
            break;
        case FEATURETYPE:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeFeatureType((RevFeatureType) revObject, "featuretype");
                    out.finish();
                }
            });
            break;
        case TAG:
            context.setResponseContent(new CommandResponse() {

                @Override
                public void write(ResponseWriter out) throws Exception {
                    out.start();
                    out.writeTag((RevTag) revObject, "tag");
                    out.finish();
                }
            });
            break;
    }
}
Also used : Context(org.locationtech.geogig.api.Context) CommandContext(org.locationtech.geogig.web.api.CommandContext) RevTag(org.locationtech.geogig.api.RevTag) RevObject(org.locationtech.geogig.api.RevObject) ResponseWriter(org.locationtech.geogig.web.api.ResponseWriter) RevFeature(org.locationtech.geogig.api.RevFeature) CommandResponse(org.locationtech.geogig.web.api.CommandResponse) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) CommandSpecException(org.locationtech.geogig.web.api.CommandSpecException) RevTree(org.locationtech.geogig.api.RevTree) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 9 with RevTag

use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.

the class ResponseWriter method writeTagListResponse.

/**
     * Writes the response for the {@link TagWebOp} command to the stream.
     * 
     * @param tags the list of {@link RevTag}s of this repository
     * @throws XMLStreamException
     */
public void writeTagListResponse(List<RevTag> tags) throws XMLStreamException {
    for (RevTag tag : tags) {
        out.writeStartElement("Tag");
        writeElement("name", tag.getName());
        out.writeEndElement();
    }
}
Also used : RevTag(org.locationtech.geogig.api.RevTag)

Example 10 with RevTag

use of org.locationtech.geogig.api.RevTag in project GeoGig by boundlessgeo.

the class TagListOp method _call.

@Override
protected ImmutableList<RevTag> _call() {
    List<Ref> refs = Lists.newArrayList(command(ForEachRef.class).setPrefixFilter(Ref.TAGS_PREFIX).call());
    List<RevTag> list = Lists.newArrayList();
    for (Ref ref : refs) {
        Optional<RevTag> tag = command(RevObjectParse.class).setObjectId(ref.getObjectId()).call(RevTag.class);
        list.add(tag.get());
    }
    return ImmutableList.copyOf(list);
}
Also used : Ref(org.locationtech.geogig.api.Ref) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) RevTag(org.locationtech.geogig.api.RevTag) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef)

Aggregations

RevTag (org.locationtech.geogig.api.RevTag)16 ObjectId (org.locationtech.geogig.api.ObjectId)8 RevCommit (org.locationtech.geogig.api.RevCommit)8 RevObject (org.locationtech.geogig.api.RevObject)6 Test (org.junit.Test)4 Ref (org.locationtech.geogig.api.Ref)3 CommitOp (org.locationtech.geogig.api.porcelain.CommitOp)3 TagCreateOp (org.locationtech.geogig.api.porcelain.TagCreateOp)3 TagListOp (org.locationtech.geogig.api.porcelain.TagListOp)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Context (org.locationtech.geogig.api.Context)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 RevPerson (org.locationtech.geogig.api.RevPerson)2 RevTagImpl (org.locationtech.geogig.api.RevTagImpl)2 RevTree (org.locationtech.geogig.api.RevTree)2 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)2 CommandContext (org.locationtech.geogig.web.api.CommandContext)2 CommandResponse (org.locationtech.geogig.web.api.CommandResponse)2 Optional (com.google.common.base.Optional)1