/**
   * never return null;
   *
   * @param context
   * @return
   */
  public static String getDeviceSerial(Context context) {
    UUID uuid = null;

    final String androidId = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);

    // Use the Android ID unless it's broken, in which case fallback on deviceId,
    // unless it's not available, then fallback on a random number which we store
    // to a prefs file
    try {
      if (!"9774d56d682e549c".equals(androidId)) {
        uuid = UUID.nameUUIDFromBytes(androidId.getBytes("utf8"));
      } else {
        final String deviceId =
            ((TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
        uuid =
            deviceId != null
                ? UUID.nameUUIDFromBytes(deviceId.getBytes("utf8"))
                : UUID.randomUUID();
      }
    } catch (UnsupportedEncodingException e) {
      Log.w(TAG, "exception", e);
      uuid = UUID.randomUUID();
    }

    return uuid.toString();
  }
Example #2
0
  private static void addPacket(
      Player p, String msg, int slotId, WrappedGameProfile gameProfile, boolean b, int ping) {
    PacketContainer message = protocolManager.createPacket(PacketType.Play.Server.PLAYER_INFO);
    String nameToShow = (!shuttingdown ? "$" : "") + msg;
    if (protocolManager.getProtocolVersion(p) >= 47) {
      nameToShow =
          (!shuttingdown ? "$" : "")
              + ChatColor.DARK_GRAY
              + slotId
              + ": "
              + msg.substring(0, Math.min(msg.length(), 10));
    }
    EnumWrappers.PlayerInfoAction action;
    if (b) {
      action = EnumWrappers.PlayerInfoAction.ADD_PLAYER;
    } else {
      action = EnumWrappers.PlayerInfoAction.REMOVE_PLAYER;
    }
    message.getPlayerInfoAction().write(0, action);
    List<PlayerInfoData> pInfoData = new ArrayList<PlayerInfoData>();
    if (gameProfile != null) {
      pInfoData.add(
          new PlayerInfoData(
              gameProfile
                  .withName(nameToShow.substring(1))
                  .withId(
                      UUID.nameUUIDFromBytes(
                              ("OfflinePlayer:" + nameToShow.substring(1)).getBytes(Charsets.UTF_8))
                          .toString()),
              ping,
              EnumWrappers.NativeGameMode.SURVIVAL,
              WrappedChatComponent.fromText(nameToShow)));
    } else {
      pInfoData.add(
          new PlayerInfoData(
              new WrappedGameProfile(
                  UUID.nameUUIDFromBytes(
                      ("OfflinePlayer:" + nameToShow.substring(1)).getBytes(Charsets.UTF_8)),
                  nameToShow.substring(1)),
              ping,
              EnumWrappers.NativeGameMode.SURVIVAL,
              WrappedChatComponent.fromText(nameToShow)));
    }

    message.getPlayerInfoDataLists().write(0, pInfoData);
    List<PacketContainer> packetList = cachedPackets.get(p);
    if (packetList == null) {
      packetList = new ArrayList<PacketContainer>();
      cachedPackets.put(p, packetList);
    }
    packetList.add(message);
  }
Example #3
0
 @Test
 public void testCreateWithDelegate_UUID() throws Exception {
   UUID uuid = UUID.nameUUIDFromBytes("uuid".getBytes());
   BiochemicalReaction rxn = BiochemRxnImpl.createWithDelegate(uuid);
   assertNotNull(rxn.getMetabolicReaction());
   assertThat(rxn.getMetabolicReaction().uuid(), is(uuid));
 }
Example #4
0
  public List<TransferredResource> createCorpora()
      throws InterruptedException, IOException, FileAlreadyExistsException, NotFoundException,
          GenericException, AlreadyExistsException, SolrServerException, IsStillUpdatingException {
    TransferredResourcesScanner f = RodaCoreFactory.getTransferredResourcesScanner();

    List<TransferredResource> resources = new ArrayList<TransferredResource>();

    Path corpora =
        corporaPath
            .resolve(RodaConstants.STORAGE_CONTAINER_AIP)
            .resolve(CorporaConstants.SOURCE_AIP_CONVERTER_3)
            .resolve(RodaConstants.STORAGE_DIRECTORY_REPRESENTATIONS)
            .resolve(CorporaConstants.REPRESENTATION_CONVERTER_ID_3)
            .resolve(RodaConstants.STORAGE_DIRECTORY_DATA);

    String transferredResourceId = "testt";
    FSUtils.copy(corpora, f.getBasePath().resolve(transferredResourceId), true);

    f.updateTransferredResources(Optional.empty(), true);
    index.commit(TransferredResource.class);

    resources.add(
        index.retrieve(
            TransferredResource.class,
            UUID.nameUUIDFromBytes(transferredResourceId.getBytes()).toString()));
    return resources;
  }
Example #5
0
 @Test
 @SuppressWarnings("unchecked")
 public void modificationDuringTransactionCausesAbort() throws Exception {
   Map<String, String> testMap =
       getRuntime().getObjectsView().open(CorfuRuntime.getStreamID("A"), SMRMap.class);
   assertThat(testMap.put("a", "z"));
   getRuntime().getObjectsView().TXBegin();
   assertThat(testMap.put("a", "a")).isEqualTo("z");
   assertThat(testMap.put("a", "b")).isEqualTo("a");
   assertThat(testMap.get("a")).isEqualTo("b");
   CompletableFuture cf =
       CompletableFuture.runAsync(
           () -> {
             Map<String, String> testMap2 =
                 getRuntime()
                     .getObjectsView()
                     .open(
                         UUID.nameUUIDFromBytes("A".getBytes()),
                         SMRMap.class,
                         null,
                         EnumSet.of(ObjectOpenOptions.NO_CACHE),
                         SerializerType.JSON);
             testMap2.put("a", "f");
           });
   cf.join();
   assertThatThrownBy(() -> getRuntime().getObjectsView().TXEnd())
       .isInstanceOf(TransactionAbortedException.class);
 }
Example #6
0
  @Override
  public void uncaughtException(Thread arg0, Throwable arg1) {
    // 把错误的堆栈信息 获取出来
    String errorInfo = getErrorInfo(arg1);
    String uuidKey = UUID.nameUUIDFromBytes(errorInfo.getBytes()).toString();

    String existsException = Utils.getSharedPreferences("uncaughtException").getString(uuidKey, "");
    if (!existsException.equals("")) {
      // -- this uncaughtException has got
      Debug.Log("Exception has got yet: " + errorInfo);
      Debug.Log("kill self() ");
      android.os.Process.killProcess(android.os.Process.myPid());
      return;
    }

    Editor editor = Utils.getSharedPreferences("uncaughtException").edit();
    editor.putString(uuidKey, "Mark");
    editor.commit();

    String content = DeviceInfo.getInfo(context).toString();
    String msg = content + "\nStack:\n" + errorInfo;

    Debug.Log("uncaughtException: " + msg);

    errorContent = msg;

    //        sendExceptionMsg();
  }
 public DeleteStoragePoolCommand(StoragePool pool) {
   this(
       pool,
       LOCAL_PATH_PREFIX
           + File.separator
           + UUID.nameUUIDFromBytes((pool.getHostAddress() + pool.getPath()).getBytes()));
 }
  @Test
  public void shouldSavePlayerData() {
    // given
    Player player = mock(Player.class);
    UUID uuid = UUID.nameUUIDFromBytes("New player".getBytes());
    given(player.getUniqueId()).willReturn(uuid);
    given(permissionsManager.getPrimaryGroup(player)).willReturn("primary-grp");
    given(player.isOp()).willReturn(true);
    given(player.getWalkSpeed()).willReturn(1.2f);
    given(player.getFlySpeed()).willReturn(0.8f);
    given(player.getAllowFlight()).willReturn(true);

    World world = mock(World.class);
    given(world.getName()).willReturn("player-world");
    Location location = new Location(world, 0.2, 102.25, -89.28, 3.02f, 90.13f);
    given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(location);

    // when
    limboPlayerStorage.saveData(player);

    // then
    File playerFile =
        new File(dataFolder, FileUtils.makePath("playerdata", uuid.toString(), "data.json"));
    assertThat(playerFile.exists(), equalTo(true));
    // TODO ljacqu 20160711: Check contents of file
  }
Example #9
0
 public static String fromSeed(String seed) {
   StringBuilder sb = new StringBuilder();
   UUID uuid = UUID.nameUUIDFromBytes(seed.getBytes());
   sb.append(
       String.format("%016x%016x", uuid.getMostSignificantBits(), uuid.getLeastSignificantBits()));
   return sb.toString();
 }
Example #10
0
 static {
   try {
     emptyVersion = UUID.nameUUIDFromBytes(MessageDigest.getInstance("MD5").digest());
   } catch (NoSuchAlgorithmException e) {
     throw new AssertionError();
   }
 }
Example #11
0
  @Test
  public void testCreatePrimaryStorage() {
    DataStoreProvider provider =
        dataStoreProviderMgr.getDataStoreProvider("sample primary data store provider");
    Map<String, Object> params = new HashMap<String, Object>();
    URI uri = null;
    try {
      uri = new URI(this.getPrimaryStorageUrl());
    } catch (URISyntaxException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    params.put("url", this.getPrimaryStorageUrl());
    params.put("server", uri.getHost());
    params.put("path", uri.getPath());
    params.put("protocol", StoragePoolType.NetworkFilesystem);
    params.put("dcId", dcId.toString());
    params.put("clusterId", clusterId.toString());
    params.put("name", this.primaryName);
    params.put("port", "1");
    params.put("roles", DataStoreRole.Primary.toString());
    params.put("uuid", UUID.nameUUIDFromBytes(this.getPrimaryStorageUrl().getBytes()).toString());
    params.put("providerName", String.valueOf(provider.getName()));

    DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
    this.primaryStore = lifeCycle.initialize(params);
    ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
    lifeCycle.attachCluster(this.primaryStore, scope);
  }
Example #12
0
 private static void a(Context paramContext, File paramFile) {
   FileOutputStream localFileOutputStream = new FileOutputStream(paramFile);
   byte[] arrayOfByte1 =
       Settings.Secure.getString(paramContext.getContentResolver(), "android_id").getBytes();
   Time localTime = new Time();
   localTime.setToNow();
   byte[] arrayOfByte2 = new byte[6 + arrayOfByte1.length];
   for (int i = 0; ; i++) {
     if (i >= arrayOfByte1.length) {
       int j = i + 1;
       arrayOfByte2[i] = ((byte) localTime.year);
       int k = j + 1;
       arrayOfByte2[j] = ((byte) localTime.month);
       int m = k + 1;
       arrayOfByte2[k] = ((byte) localTime.monthDay);
       int n = m + 1;
       arrayOfByte2[m] = ((byte) localTime.hour);
       int i1 = n + 1;
       arrayOfByte2[n] = ((byte) localTime.minute);
       arrayOfByte2[i1] = ((byte) localTime.second);
       String str = UUID.nameUUIDFromBytes(arrayOfByte2).toString();
       System.out.println("uuid.." + str);
       localFileOutputStream.write(str.getBytes());
       return;
     }
     arrayOfByte2[i] = arrayOfByte1[i];
   }
 }
 public UUID getRelHash() {
   if (relHash_ == null) {
     relHash_ =
         UUID.nameUUIDFromBytes(new String(rel + rela + sourceUUID_ + targetUUID_).getBytes());
   }
   return relHash_;
 }
Example #14
0
  @JsonIgnore
  public UUID getId() {
    if (id == null) {
      id = UUID.nameUUIDFromBytes(getIdString().getBytes());
    }

    return id;
  }
Example #15
0
 /**
  * @param identifier
  * @return a generated id for the given string identifier
  */
 static String getId(String identifier) {
   try {
     // TODO find a better algorithm, UUID is using MD5
     return UUID.nameUUIDFromBytes(identifier.getBytes("UTF-8")).toString();
   } catch (UnsupportedEncodingException e) {
     throw new IllegalStateException(e);
   }
 }
Example #16
0
  /**
   * The generated UUID of a page is based on the Wiki name and the page name (or path).
   *
   * @param p
   * @return
   * @throws IOException
   */
  private String mkUuid(String wiki, String name) throws IOException {
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    out.write(wiki.getBytes("UTF-8"));
    out.write(name.getBytes("UTF-8"));

    return UUID.nameUUIDFromBytes(out.toByteArray()).toString();
  }
  @Test
  public void testSerialization() {
    MessagePack msgpack = new MessagePack();
    msgpack.register(
        RexProMessageMeta.class, RexProMessageMeta.SerializationTemplate.getInstance());
    msgpack.register(RexProBindings.class, RexProBindings.SerializationTemplate.getInstance());
    msgpack.register(
        RexProScriptResult.class, RexProScriptResult.SerializationTemplate.getInstance());

    ConsoleScriptResponseMessage outMsg = new ConsoleScriptResponseMessage();
    outMsg.setRequestAsUUID(UUID.randomUUID());
    outMsg.setSessionAsUUID(UUID.randomUUID());
    outMsg.ConsoleLines = new String[2];
    outMsg.ConsoleLines[0] = "a";
    outMsg.ConsoleLines[1] = "b";
    outMsg.Bindings.put("o", 1);

    final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    final Packer packer = msgpack.createPacker(outStream);
    try {
      packer.write(outMsg);
      packer.close();
    } catch (IOException ex) {
      Assert.fail();
    }

    byte[] bytes = outStream.toByteArray();

    final ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    final Unpacker unpacker = msgpack.createUnpacker(in);

    ConsoleScriptResponseMessage inMsg;
    try {
      inMsg = unpacker.read(ConsoleScriptResponseMessage.class);
      Assert.assertEquals(outMsg.Meta, inMsg.Meta);
      Assert.assertEquals(
          UUID.nameUUIDFromBytes(outMsg.Request), UUID.nameUUIDFromBytes(inMsg.Request));
      Assert.assertEquals(
          UUID.nameUUIDFromBytes(outMsg.Session), UUID.nameUUIDFromBytes(inMsg.Session));
      Assert.assertTrue(Arrays.deepEquals(outMsg.ConsoleLines, inMsg.ConsoleLines));
      Assert.assertEquals(inMsg.Bindings.get("o"), 1);
    } catch (IOException ex) {
      Assert.fail();
    }
  }
    @Override
    public void run() {
      boolean verify =
          this.session.hasFlag(MinecraftConstants.VERIFY_USERS_KEY)
              ? this.session.<Boolean>getFlag(MinecraftConstants.VERIFY_USERS_KEY)
              : true;

      GameProfile profile = null;
      if (verify && this.key != null) {
        Proxy proxy = this.session.<Proxy>getFlag(MinecraftConstants.AUTH_PROXY_KEY);
        if (proxy == null) {
          proxy = Proxy.NO_PROXY;
        }

        try {
          profile =
              new SessionService(proxy)
                  .getProfileByServer(
                      username,
                      new BigInteger(
                              CryptUtil.getServerIdHash(serverId, KEY_PAIR.getPublic(), this.key))
                          .toString(16));
        } catch (RequestException e) {
          this.session.disconnect("Failed to make session service request.", e);
          return;
        }

        if (profile == null) {
          this.session.disconnect("Failed to verify username.");
        }
      } else {
        profile =
            new GameProfile(
                UUID.nameUUIDFromBytes(("OfflinePlayer:" + username).getBytes()), username);
      }

      int threshold;
      if (this.session.hasFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD)) {
        threshold = this.session.getFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD);
      } else {
        threshold = 256;
      }

      this.session.send(new LoginSetCompressionPacket(threshold));
      this.session.setCompressionThreshold(threshold);
      this.session.send(new LoginSuccessPacket(profile));
      this.session.setFlag(MinecraftConstants.PROFILE_KEY, profile);
      ((MinecraftProtocol) this.session.getPacketProtocol())
          .setSubProtocol(SubProtocol.GAME, false, this.session);
      ServerLoginHandler handler =
          this.session.getFlag(MinecraftConstants.SERVER_LOGIN_HANDLER_KEY);
      if (handler != null) {
        handler.loggedIn(this.session);
      }

      new Thread(new KeepAliveTask(this.session)).start();
    }
Example #19
0
 public static String makeGUID(
     final String catalog, final String schema, final String table, final String column) {
   final String t =
       StringUtils.defaultString(catalog)
           + StringUtils.defaultString(schema)
           + StringUtils.defaultString(table)
           + StringUtils.defaultString(column);
   return "v_" + (UUID.nameUUIDFromBytes(t.getBytes()).toString().replace("-", "_"));
 }
 public AttributeModifier build() {
   AttributeModifier modifier =
       new AttributeModifier(
           UUID.nameUUIDFromBytes(name.getBytes(StandardCharsets.US_ASCII)),
           name,
           value,
           operation.ordinal());
   modifier.setSaved(isSaved);
   return modifier;
 }
  public UUID getInverseRelHash(RRFBaseConverterMojo bc) {
    // reverse the direction of the rels, and the source/target
    String relInverse = bc.nameToRel_.get(rel).getFSNName();
    String relaInverse = null;
    if (rela != null) {
      relaInverse = bc.nameToRel_.get(rela).getFSNName();
    }

    return UUID.nameUUIDFromBytes(
        new String(relInverse + relaInverse + targetUUID_ + sourceUUID_).getBytes());
  }
Example #22
0
 @Override
 public AuthenticationResponse authenticate(String username, Object... aditionalArgs) {
   AuthenticationResponse response =
       new AuthenticationResponse(
           true, "redstonelamp.authSuccess", UUID.nameUUIDFromBytes(username.getBytes()));
   if (getManager().getServer().getOnlinePlayers().size()
       > getManager().getServer().getMaxPlayers()) {
     response = new AuthenticationResponse(false, "redstonelamp.authFailed.serverFull", null);
   }
   return response;
 }
  @Test
  public void shouldReturnIfHasData() {
    // given
    Player player1 = mock(Player.class);
    given(player1.getUniqueId()).willReturn(SAMPLE_UUID);
    Player player2 = mock(Player.class);
    given(player2.getUniqueId()).willReturn(UUID.nameUUIDFromBytes("not-stored".getBytes()));

    // when / then
    assertThat(limboPlayerStorage.hasData(player1), equalTo(true));
    assertThat(limboPlayerStorage.hasData(player2), equalTo(false));
  }
  @Test
  public void shouldReturnNullForUnavailablePlayer() {
    // given
    Player player = mock(Player.class);
    given(player.getUniqueId()).willReturn(UUID.nameUUIDFromBytes("other-player".getBytes()));

    // when
    LimboPlayer data = limboPlayerStorage.readData(player);

    // then
    assertThat(data, nullValue());
  }
Example #25
0
public final class d {
  private static String a = null;
  private static final String b = "INSTALLATION-" + UUID.nameUUIDFromBytes("androidkit".getBytes());

  public static String a(Context paramContext) {
    try {
      File localFile;
      if (a == null) localFile = new File(paramContext.getFilesDir(), b);
      try {
        if (!localFile.exists()) a(paramContext, localFile);
        RandomAccessFile localRandomAccessFile = new RandomAccessFile(localFile, "r");
        byte[] arrayOfByte = new byte[(int) localRandomAccessFile.length()];
        localRandomAccessFile.readFully(arrayOfByte);
        localRandomAccessFile.close();
        a = new String(arrayOfByte);
        String str = a;
        return str;
      } catch (IOException localIOException) {
        while (true) localIOException.printStackTrace();
      }
    } finally {
    }
  }

  private static void a(Context paramContext, File paramFile) {
    FileOutputStream localFileOutputStream = new FileOutputStream(paramFile);
    byte[] arrayOfByte1 =
        Settings.Secure.getString(paramContext.getContentResolver(), "android_id").getBytes();
    Time localTime = new Time();
    localTime.setToNow();
    byte[] arrayOfByte2 = new byte[6 + arrayOfByte1.length];
    for (int i = 0; ; i++) {
      if (i >= arrayOfByte1.length) {
        int j = i + 1;
        arrayOfByte2[i] = ((byte) localTime.year);
        int k = j + 1;
        arrayOfByte2[j] = ((byte) localTime.month);
        int m = k + 1;
        arrayOfByte2[k] = ((byte) localTime.monthDay);
        int n = m + 1;
        arrayOfByte2[m] = ((byte) localTime.hour);
        int i1 = n + 1;
        arrayOfByte2[n] = ((byte) localTime.minute);
        arrayOfByte2[i1] = ((byte) localTime.second);
        String str = UUID.nameUUIDFromBytes(arrayOfByte2).toString();
        System.out.println("uuid.." + str);
        localFileOutputStream.write(str.getBytes());
        return;
      }
      arrayOfByte2[i] = arrayOfByte1[i];
    }
  }
}
 // [JACKSON-726]
 public void testUUIDKeyMap() throws Exception {
   ObjectMapper mapper = new ObjectMapper();
   UUID key = UUID.nameUUIDFromBytes("foobar".getBytes("UTF-8"));
   String JSON = "{ \"" + key + "\":4}";
   Map<UUID, Object> result = mapper.readValue(JSON, new TypeReference<Map<UUID, Object>>() {});
   assertNotNull(result);
   assertEquals(1, result.size());
   Object ob = result.keySet().iterator().next();
   assertNotNull(ob);
   assertEquals(UUID.class, ob.getClass());
   assertEquals(key, ob);
 }
Example #27
0
  public DataStore createPrimaryDataStore() {
    try {
      DataStoreProvider provider =
          dataStoreProviderMgr.getDataStoreProvider("sample primary data store provider");
      Map<String, Object> params = new HashMap<String, Object>();
      URI uri = new URI(this.getPrimaryStorageUrl());
      params.put("url", this.getPrimaryStorageUrl());
      params.put("server", uri.getHost());
      params.put("path", uri.getPath());
      params.put("protocol", Storage.StoragePoolType.NetworkFilesystem);
      params.put("dcId", dcId.toString());
      params.put("clusterId", clusterId.toString());
      params.put("name", this.primaryName);
      params.put("port", "1");
      params.put("roles", DataStoreRole.Primary.toString());
      params.put("uuid", UUID.nameUUIDFromBytes(this.getPrimaryStorageUrl().getBytes()).toString());
      params.put("providerName", String.valueOf(provider.getName()));

      DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
      DataStore store = lifeCycle.initialize(params);
      ClusterScope scope = new ClusterScope(clusterId, podId, dcId);
      lifeCycle.attachCluster(store, scope);

      /*
       * PrimaryDataStoreProvider provider =
       * primaryDataStoreProviderMgr.getDataStoreProvider
       * ("sample primary data store provider");
       * primaryDataStoreProviderMgr.configure("primary data store mgr",
       * new HashMap<String, Object>());
       *
       * List<PrimaryDataStoreVO> ds =
       * primaryStoreDao.findPoolByName(this.primaryName); if (ds.size()
       * >= 1) { PrimaryDataStoreVO store = ds.get(0); if
       * (store.getRemoved() == null) { return
       * provider.getDataStore(store.getId()); } }
       *
       *
       * Map<String, String> params = new HashMap<String, String>();
       * params.put("url", this.getPrimaryStorageUrl());
       * params.put("dcId", dcId.toString()); params.put("clusterId",
       * clusterId.toString()); params.put("name", this.primaryName);
       * PrimaryDataStoreInfo primaryDataStoreInfo =
       * provider.registerDataStore(params); PrimaryDataStoreLifeCycle lc
       * = primaryDataStoreInfo.getLifeCycle(); ClusterScope scope = new
       * ClusterScope(clusterId, podId, dcId); lc.attachCluster(scope);
       * return primaryDataStoreInfo;
       */
      return store;
    } catch (Exception e) {
      return null;
    }
  }
Example #28
0
  private static String genKeyFromMap(Map map) {
    StringBuilder mapToString = new StringBuilder();

    Set<Map.Entry<Writable, WritableComparable>> entrySet = map.entrySet();
    for (Map.Entry<Writable, WritableComparable> entry : entrySet) {
      mapToString.append(entry.getKey().toString()).append(":");
      mapToString.append(entry.getValue().toString()).append(";");
    }

    logger.info("Map as string: " + mapToString.toString());

    return UUID.nameUUIDFromBytes(mapToString.toString().getBytes()).toString();
  }
  public DataStore createPrimaryDataStore() {
    try {
      String uuid = UUID.nameUUIDFromBytes(this.getPrimaryStorageUrl().getBytes()).toString();
      List<StoragePoolVO> pools = primaryDataStoreDao.findPoolByName(this.primaryName);
      if (pools.size() > 0) {
        return this.dataStoreMgr.getPrimaryDataStore(pools.get(0).getId());
      }

      /*
       * DataStoreProvider provider =
       * dataStoreProviderMgr.getDataStoreProvider
       * ("cloudstack primary data store provider"); Map<String, Object>
       * params = new HashMap<String, Object>(); URI uri = new
       * URI(this.getPrimaryStorageUrl()); params.put("url",
       * this.getPrimaryStorageUrl()); params.put("server",
       * uri.getHost()); params.put("path", uri.getPath());
       * params.put("protocol",
       * Storage.StoragePoolType.NetworkFilesystem); params.put("zoneId",
       * dcId); params.put("clusterId", clusterId); params.put("name",
       * this.primaryName); params.put("port", 1); params.put("podId",
       * this.podId); params.put("roles",
       * DataStoreRole.Primary.toString()); params.put("uuid", uuid);
       * params.put("providerName", String.valueOf(provider.getName()));
       *
       * DataStoreLifeCycle lifeCycle = provider.getDataStoreLifeCycle();
       * DataStore store = lifeCycle.initialize(params); ClusterScope
       * scope = new ClusterScope(clusterId, podId, dcId);
       * lifeCycle.attachCluster(store, scope);
       */

      StoragePoolVO pool = new StoragePoolVO();
      pool.setClusterId(clusterId);
      pool.setDataCenterId(dcId);
      URI uri = new URI(this.getPrimaryStorageUrl());
      pool.setHostAddress(uri.getHost());
      pool.setPath(uri.getPath());
      pool.setPort(0);
      pool.setName(this.primaryName);
      pool.setUuid(this.getPrimaryStorageUuid());
      pool.setStatus(StoragePoolStatus.Up);
      pool.setPoolType(StoragePoolType.VMFS);
      pool.setPodId(podId);
      pool.setScope(ScopeType.CLUSTER);
      pool.setStorageProviderName("cloudstack primary data store provider");
      pool = this.primaryStoreDao.persist(pool);
      DataStore store = this.dataStoreMgr.getPrimaryDataStore(pool.getId());
      return store;
    } catch (Exception e) {
      return null;
    }
  }
Example #30
0
  @Override
  public guid key() {
    if (key == null) {
      String ownerName = owner != null ? owner.name() : null;
      String name = name();

      if (name == null) throw new UnsupportedOperationException();

      String value = (ownerName != null ? ownerName + "." : "") + name;
      key = new guid(UUID.nameUUIDFromBytes(value.getBytes()));
    }

    return key;
  }