Search in sources :

Example 6 with ShipmentId

use of org.apache.geode.internal.cache.execute.data.ShipmentId in project geode by apache.

the class CustomerFixedPartitionResolver method getPartitionName.

public String getPartitionName(EntryOperation opDetails, Set allAvailablePartitions) {
    int customerID = -1;
    if (opDetails.getKey() instanceof ShipmentId) {
        ShipmentId shipmentId = (ShipmentId) opDetails.getKey();
        customerID = shipmentId.getOrderId().getCustId().getCustId();
    }
    if (opDetails.getKey() instanceof OrderId) {
        OrderId orderId = (OrderId) opDetails.getKey();
        customerID = orderId.getCustId().getCustId();
    } else if (opDetails.getKey() instanceof CustId) {
        CustId custId = (CustId) opDetails.getKey();
        customerID = custId.getCustId();
    }
    if (customerID >= 1 && customerID <= 10) {
        return "10";
    } else if (customerID > 10 && customerID <= 20) {
        return "20";
    } else if (customerID > 20 && customerID <= 30) {
        return "30";
    } else if (customerID > 30 && customerID <= 40) {
        return "40";
    } else {
        return "Invalid";
    }
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) CustId(org.apache.geode.internal.cache.execute.data.CustId) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 7 with ShipmentId

use of org.apache.geode.internal.cache.execute.data.ShipmentId in project geode by apache.

the class CustomerFixedPartitionResolver method getRoutingObject.

public Serializable getRoutingObject(EntryOperation opDetails) {
    Serializable routingbject = null;
    if (opDetails.getKey() instanceof ShipmentId) {
        ShipmentId shipmentId = (ShipmentId) opDetails.getKey();
        routingbject = shipmentId.getOrderId().getCustId();
    }
    if (opDetails.getKey() instanceof OrderId) {
        OrderId orderId = (OrderId) opDetails.getKey();
        routingbject = orderId.getCustId();
    } else if (opDetails.getKey() instanceof CustId) {
        CustId custId = (CustId) opDetails.getKey();
        routingbject = custId.getCustId();
    }
    return routingbject;
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) DataSerializable(org.apache.geode.DataSerializable) Serializable(java.io.Serializable) CustId(org.apache.geode.internal.cache.execute.data.CustId) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Example 8 with ShipmentId

use of org.apache.geode.internal.cache.execute.data.ShipmentId in project geode by apache.

the class FixedPartitioningTestBase method putShipmentPartitionedRegion_Persistence.

public static void putShipmentPartitionedRegion_Persistence(String partitionedRegionName) {
    assertNotNull(cache);
    Region partitionedregion = cache.getRegion(Region.SEPARATOR + partitionedRegionName);
    assertNotNull(partitionedregion);
    for (int i = 1; i <= 20; i++) {
        CustId custid = new CustId(i);
        for (int j = 1; j <= 10; j++) {
            int oid = (i * 10) + j;
            OrderId orderId = new OrderId(oid, custid);
            for (int k = 1; k <= 10; k++) {
                int sid = (oid * 10) + k;
                ShipmentId shipmentId = new ShipmentId(sid, orderId);
                Shipment shipment = new Shipment("Shipment" + sid);
                try {
                    partitionedregion.put(shipmentId, shipment);
                } catch (Exception e) {
                    org.apache.geode.test.dunit.Assert.fail("putShipmentPartitionedRegion : failed while doing put operation in ShipmentPartitionedRegion ", e);
                }
                LogWriterUtils.getLogWriter().info("Shipment :- { " + shipmentId + " : " + shipment + " }");
            }
        }
    }
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) Shipment(org.apache.geode.internal.cache.execute.data.Shipment) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 9 with ShipmentId

use of org.apache.geode.internal.cache.execute.data.ShipmentId in project geode by apache.

the class FixedPartitioningTestBase method validateAfterPutPartitionedRegion.

public static void validateAfterPutPartitionedRegion(String customerPartitionedRegionName, String orderPartitionedRegionName, String shipmentPartitionedRegionName) throws ClassNotFoundException {
    assertNotNull(cache);
    PartitionedRegion customerPartitionedregion = null;
    PartitionedRegion orderPartitionedregion = null;
    PartitionedRegion shipmentPartitionedregion = null;
    try {
        customerPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + customerPartitionedRegionName);
        orderPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + orderPartitionedRegionName);
        shipmentPartitionedregion = (PartitionedRegion) cache.getRegion(Region.SEPARATOR + shipmentPartitionedRegionName);
    } catch (Exception e) {
        org.apache.geode.test.dunit.Assert.fail("validateAfterPutPartitionedRegion : failed while getting the region", e);
    }
    assertNotNull(customerPartitionedregion);
    for (int i = 0; i < 10; i++) {
        InternalDistributedMember idmForCustomer = customerPartitionedregion.getBucketPrimary(i);
        InternalDistributedMember idmForOrder = orderPartitionedregion.getBucketPrimary(i);
        InternalDistributedMember idmForShipment = shipmentPartitionedregion.getBucketPrimary(i);
        // take all the keys from the shipment for each bucket
        Set customerKey = customerPartitionedregion.getBucketKeys(i);
        assertNotNull(customerKey);
        Iterator customerIterator = customerKey.iterator();
        while (customerIterator.hasNext()) {
            CustId custId = (CustId) customerIterator.next();
            assertNotNull(customerPartitionedregion.get(custId));
            Set orderKey = orderPartitionedregion.getBucketKeys(i);
            assertNotNull(orderKey);
            Iterator orderIterator = orderKey.iterator();
            while (orderIterator.hasNext()) {
                OrderId orderId = (OrderId) orderIterator.next();
                if (custId.equals(orderId.getCustId())) {
                    LogWriterUtils.getLogWriter().info(orderId + "belongs to node " + idmForCustomer + " " + idmForOrder);
                    assertEquals(idmForCustomer, idmForOrder);
                }
                Set shipmentKey = shipmentPartitionedregion.getBucketKeys(i);
                assertNotNull(shipmentKey);
                Iterator shipmentIterator = shipmentKey.iterator();
                while (shipmentIterator.hasNext()) {
                    ShipmentId shipmentId = (ShipmentId) shipmentIterator.next();
                    // assertNotNull(shipmentPartitionedregion.get(shipmentId));
                    if (orderId.equals(shipmentId.getOrderId())) {
                        LogWriterUtils.getLogWriter().info(shipmentId + "belongs to node " + idmForOrder + " " + idmForShipment);
                    }
                }
            }
        }
    }
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CustId(org.apache.geode.internal.cache.execute.data.CustId) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Iterator(java.util.Iterator) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 10 with ShipmentId

use of org.apache.geode.internal.cache.execute.data.ShipmentId in project geode by apache.

the class CustomerIDPartitionResolver method getRoutingObject.

public Serializable getRoutingObject(EntryOperation opDetails) {
    Serializable routingbject = null;
    if (opDetails.getKey() instanceof ShipmentId) {
        ShipmentId shipmentId = (ShipmentId) opDetails.getKey();
        routingbject = shipmentId.getOrderId().getCustId();
    }
    if (opDetails.getKey() instanceof OrderId) {
        OrderId orderId = (OrderId) opDetails.getKey();
        routingbject = orderId.getCustId();
    } else if (opDetails.getKey() instanceof CustId) {
        CustId custId = (CustId) opDetails.getKey();
        routingbject = custId.getCustId();
    }
    return routingbject;
}
Also used : ShipmentId(org.apache.geode.internal.cache.execute.data.ShipmentId) Serializable(java.io.Serializable) CustId(org.apache.geode.internal.cache.execute.data.CustId) OrderId(org.apache.geode.internal.cache.execute.data.OrderId)

Aggregations

OrderId (org.apache.geode.internal.cache.execute.data.OrderId)25 ShipmentId (org.apache.geode.internal.cache.execute.data.ShipmentId)25 CustId (org.apache.geode.internal.cache.execute.data.CustId)23 Shipment (org.apache.geode.internal.cache.execute.data.Shipment)11 Region (org.apache.geode.cache.Region)10 IOException (java.io.IOException)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 ParseException (java.text.ParseException)5 HARegion (org.apache.geode.internal.cache.HARegion)4 Order (org.apache.geode.internal.cache.execute.data.Order)4 IgnoredException (org.apache.geode.test.dunit.IgnoredException)4 Serializable (java.io.Serializable)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Set (java.util.Set)3 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 ExecutionException (java.util.concurrent.ExecutionException)2 CacheClosedException (org.apache.geode.cache.CacheClosedException)2