-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DDP-5671 added script to allow bulk cancellation of orders in GBF #126
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.broadinstitute.dsm.model.gbf; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class CancelRequest { | ||
|
||
@SerializedName("orderNumber") | ||
private String orderNumber; | ||
|
||
public CancelRequest(String orderNumber) { | ||
this.orderNumber = orderNumber; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.broadinstitute.dsm.model.gbf; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class CancelResponse { | ||
|
||
@SerializedName("orderNumber") | ||
private String orderNumber; | ||
|
||
@SerializedName("orderStatus") | ||
private String orderStatus; | ||
|
||
@SerializedName("success") | ||
private Boolean success; | ||
|
||
@SerializedName("errorMessage") | ||
private String errorMessage; | ||
|
||
public String getOrderNumber() { | ||
return orderNumber; | ||
} | ||
|
||
public String getOrderStatus() { | ||
return orderStatus; | ||
} | ||
|
||
public boolean wasSuccessful() { | ||
return Boolean.TRUE.equals(success); | ||
} | ||
|
||
public String getErrorMessage() { | ||
return errorMessage; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.broadinstitute.dsm.util.externalShipper; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.broadinstitute.dsm.model.gbf.CancelResponse; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class CancelGBFOrderCLI { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(CancelGBFOrderCLI.class); | ||
|
||
|
||
public static void main(String[] args) { | ||
String cancelUrl = args[0]; | ||
String apiKey = args[1]; | ||
String ordersFile = args[2]; | ||
FileReader ordersReader = null; | ||
List<String> ordersToCancel = new ArrayList<>(); | ||
|
||
try { | ||
ordersReader = new FileReader(new File(ordersFile)); | ||
ordersToCancel = IOUtils.readLines(ordersReader); | ||
} catch(IOException e) { | ||
logger.error("Could read orders from file " + ordersFile,e); | ||
} | ||
|
||
if (ordersReader != null) { | ||
CancelResponse cancelResponse = null; | ||
for (String orderNumber : ordersToCancel) { | ||
try { | ||
cancelResponse = GBFRequestUtil.cancelOrder(orderNumber, cancelUrl, apiKey); | ||
if (cancelResponse.wasSuccessful()) { | ||
logger.info("Cancelled order {}", orderNumber); | ||
} else { | ||
logger.error("Could not cancel order {} due to {}",orderNumber, cancelResponse.getErrorMessage()); | ||
} | ||
} catch(Exception e) { | ||
logger.error("Could not cancel order {}", orderNumber, e); | ||
} | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import com.google.api.client.http.HttpStatusCodes; | ||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import lombok.NonNull; | ||
import org.apache.commons.lang3.NotImplementedException; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
@@ -96,15 +97,17 @@ public class GBFRequestUtil implements ExternalShipper { | |
|
||
private static Executor blindTrustEverythingExecutor; | ||
|
||
public GBFRequestUtil() { | ||
static { | ||
initTrust(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before this change, even if you were calling a static method, you would have had to new up an object, lest you would see an NPE because various static methods assume that |
||
} | ||
|
||
private static synchronized void initTrust() { | ||
try { | ||
if (blindTrustEverythingExecutor == null) { | ||
blindTrustEverythingExecutor = Executor.newInstance(SecurityUtil.buildHttpClient()); | ||
} | ||
} | ||
catch (Exception e) { | ||
} catch (Exception e) { | ||
logger.error("Starting up the blindTrustEverythingExecutor ", e); | ||
System.exit(-3); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit scary--a constructor that calls |
||
} | ||
} | ||
|
||
|
@@ -615,4 +618,23 @@ public static void markKitRequestAsOrdered(ArrayList<KitRequest> kitRequests) { | |
|
||
} | ||
|
||
public static CancelResponse cancelOrder(String orderNumber, String cancelUrl, String apiKey) throws Exception { | ||
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create(); | ||
CancelRequest cancelRequest = new CancelRequest(orderNumber); | ||
logger.info("About to cancel GBF order {}", orderNumber); | ||
CancelResponse cancelResponse = executePost(CancelResponse.class, cancelUrl, gson.toJson(cancelRequest), apiKey); | ||
|
||
if (cancelResponse != null) { | ||
if (cancelResponse.wasSuccessful()) { | ||
logger.info("Cancelled GBF order {}", orderNumber); | ||
} else { | ||
logger.error("Could not cancel GBF order " + orderNumber + " due to " + cancelResponse.getErrorMessage()); | ||
} | ||
} else { | ||
logger.error("Got no response after cancelling GBF order " + orderNumber); | ||
} | ||
return cancelResponse; | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few model classes to match the GBF APIs