Coder Social home page Coder Social logo

moji's Introduction

About

A file-like MogileFS client for Java.

Start using

You can obtain Moji from Maven Central:

Maven Central GitHub license Javadocs

Features

  • java.io.File like API
  • Supports writing streams of unknown length
  • Unit/Integration tests
  • Spring friendly
  • Tracker connection pooling with balancing between hosts and strategies for dealing with failed nodes
  • Local file system implementation for faking in tests (fm.last.moji.local.LocalFileSystemMoji)

Configuration

Using plain-old-Java

    SpringMojiBean moji = new SpringMojiBean();
    moji.setAddressesCsv("192.168.0.1:7001,192.168.0.2:7001");
    moji.setDomain("testdomain");
    moji.initialise();
    moji.setTestOnBorrow(true);

Using the Spring framework

Set some properties for your context:

    moji.tracker.address=192.168.0.1:7001,192.168.0.2:7001
    moji.domain=testdomain

Import the Moji Spring context:

    <import resource="moji-context.xml" />

Or create a Moji spring bean:

    <bean id="moji" class="fm.last.moji.spring.SpringMojiBean">
      <property name="addressesCsv" value="${moji.tracker.address}" />
      <property name="domain" value="${moji.domain}" />
      <property name="maxActive" value="${moji.pool.max.active:100}" />
      <property name="maxIdle" value="${moji.pool.max.idle:10}" />
      <property name="testOnBorrow" value="${moji.pool.test.on.borrow:true}" />
    </bean>

Usage

Create/update a remote file

    MojiFile rickRoll = moji.getFile("rick-astley");
    moji.copyToMogile(new File("never-gonna-give-you-up.mp3"), rickRoll);

Or in a given storage class:

    MojiFile rickRoll = moji.getFile("rick-astley", "music-meme");

Get the remote file size

    long length = rickRoll.length();

Rename the remote file

    rickRoll.rename("stairway-to-heaven");

Check the existence of a remote file

    MojiFile abba = moji.getFile("voulez-vous");
    if (abba.exists()) {
      ...

Delete the remote file

    abba.delete();

Download a remote file

    MojiFile fooFighters = moji.getFile("stacked-actors");
    fooFighters.copyToFile(new File("foo-fighters.mp3"));

Modify the storage class of a remote file

    fooFighters.modifyStorageClass("awesome");

Stream from a remote file

    InputStream stream = null;
    try {
      stream = fooFighters.getInputStream();
      // Do something streamy
      //   stream.read();
    } finally {
      stream.close();
    }

Stream to a remote file

This will either create a new file or overwrite an existing file's contents

    OutputStream stream = null;
    try {
      stream = fooFighters.getOutputStream();
      // Do something streamy
      //   stream.write(...);
      stream.flush();
    } finally {
      stream.close();
    }

List remote files by prefix

    List<MojiFile> files = moji.list("abba-");
    for(MojiFile file : files) {
      // abba-waterloo, abba-voulez-vous, abba-fernado, etc.
    }

Impose a limit on the number of items returned:

    List<MojiFile> files = moji.list("abba-", 10);
    for(MojiFile file : files) {
      // abba-waterloo, abba-voulez-vous, abba-fernado, etc. - maximum of 10
    }

Get the locations of a remote file

    File fooFighters = moji.getFile("in-your-honour"); 
    List<URL> paths = fooFighters.getPaths();
    // http://192.168.0.2:7500/dev2/0/000/000/0000000819.fid, http://192.168.0.4:7500/dev3/0/000/000/0000000819.fid, etc

Get the attributes of a remote file

Note: this is only supported on more recent versions of MogileFS.

    File fooFighters = moji.getFile("in-your-honour"); 
    MojiFileAttributes attributes = fooFighters.getAttibutes();
    
    String storageClass = attributes.getStorageClass();
    int deviceCount = attributes.getDeviceCount();
    int fid = attributes.getFid();

Running the integration tests

To run the integration tests, you can make use of ready-to-use docker image, or setup the environment manually. For manual setup, you need:

MogileFS integration test properties config:

  • These properties should be set in /moji.properties on the classpath.

  • Set your Tracker address with the property:

      moji.tracker.hosts
    
  • Declare your Mogile domain with the property:

      moji.domain
    
  • Declare two storage classes (class assigned here should have devcount=1 if there are multiple storage nodes in the environment) in your Mogile instance and assign them with these properties:

      test.moji.class.a
      test.moji.class.b
    
  • Choose a key prefix to avoid any key clashes with real data (you're using a test instance right?) or other tests. Otherwise we might get unexpected behaviour and file deletions:

      test.moji.key.prefix
    

Building

This project uses the Maven build system.

Contributing

All contributions are welcome. Please use the Last.fm codeformatting profile found in the lastfm-oss-config project for formatting your changes.

Legal

Copyright 2012-2017 Last.fm & The "mogilefs-moji" committers.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

moji's People

Contributors

cdwhatcott avatar chenzhang22 avatar dependabot[bot] avatar hitobat avatar hrchu avatar massdosage avatar teabot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moji's Issues

Automatically close and promote release in Sonatype on release:perform

At the moment performing a Maven release still requires manual steps of logging in to Sonatype and then closing and releasing the artifacts. This can be done as part of release:perform by using a plugin like so:

org.sonatype.plugins nexus-staging-maven-plugin 1.6.3 true sonatype-nexus-staging https://oss.sonatype.org/ true

Moji does not select recovered tracker

Given two trackers, A and B, and the following scenario:

  1. At first, moji uses tracker A and B balancedly.
  2. If tracker A is broken, (e.g., killall mogilefsd on tracker A host), moji will use tracker B only.
  3. Recover tracker A, and moji will not select tracker A anymore.

The problem is that OPS of the whole mogilefs system is only half of it should be in the end of this scenario, since available tracker is only 1/2.

Maven Dependency Failed

Your project uses :

org.apache.commons commons-pool 1.5.6

but this artifact can be rerieving with :

commons-pool commons-pool 1.5.6

Thanks.

moji.getFile() throws ConcurrentModificationException under dozens of clients hit it simultaneously

  java.util.ConcurrentModificationException
    at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
    at java.util.ArrayList$Itr.next(ArrayList.java:851)
    at fm.last.moji.tracker.pool.MultiHostTrackerPool.getAddresses(MultiHostTrackerPool.java:82)
    at fm.last.moji.impl.Executor.<init>(Executor.java:36)
    at fm.last.moji.impl.MojiFileImpl.<init>(MojiFileImpl.java:56)
    at fm.last.moji.impl.MojiImpl.getFile(MojiImpl.java:52)
    at fm.last.moji.spring.SpringMojiBean.getFile(SpringMojiBean.java:52)

I have not trace it in deep, just log it in here, and maybe someone else has the same problem.

about ManagedTrackerHost.java

hello teabot ,i have a question about [ManagedTrackerHost.java] file's line 107-118,when i execute and connect faild,ReadTimeout has been throw out,then markAsFailed method execute,resetTask has been scheduled by resetTimer,but the timer has been never cancel again,then the main method in my testwork has been never closed,and running sustainedly,i don't really know about this resetTask's meaning,and need some help!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.