Search in sources :

Example 1 with Status

use of com.microsoft.azuretools.authmanage.srvpri.step.Status in project azure-tools-for-java by Microsoft.

the class SrvPriCreationStatusDialog method createServicePrincipalAsync.

private void createServicePrincipalAsync() {
    try {
        class StatusTask implements IRunnableWithProgress, IListener<Status> {

            IProgressMonitor progressIndicator = null;

            @Override
            public void listen(Status status) {
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        if (progressIndicator != null) {
                            progressIndicator.setTaskName(status.getAction());
                        }
                        // if only action was set in the status - the info for progress indicator only - igonre for table
                        if (status.getResult() != null) {
                            TableItem item = new TableItem(table, SWT.NULL);
                            item.setText(new String[] { status.getAction(), status.getResult().toString(), status.getDetails() });
                        }
                    }
                });
            }

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                progressIndicator = monitor;
                monitor.beginTask("Creating Service Principal...", IProgressMonitor.UNKNOWN);
                for (String tid : tidSidsMap.keySet()) {
                    if (monitor.isCanceled()) {
                        Display.getDefault().asyncExec(new Runnable() {

                            @Override
                            public void run() {
                                TableItem item = new TableItem(table, SWT.NULL);
                                item.setText(new String[] { "!!! Canceled by user" });
                            }
                        });
                        return;
                    }
                    List<String> sidList = tidSidsMap.get(tid);
                    if (!sidList.isEmpty()) {
                        try {
                            Display.getDefault().asyncExec(new Runnable() {

                                @Override
                                public void run() {
                                    TableItem item = new TableItem(table, SWT.NULL);
                                    item.setText(new String[] { "tenant ID: " + tid + " ===" });
                                }
                            });
                            Date now = new Date();
                            String suffix = new SimpleDateFormat("yyyyMMddHHmmss").format(now);
                            ;
                            String authFilepath = SrvPriManager.createSp(tid, sidList, suffix, this, destinationFolder);
                            if (authFilepath != null) {
                                Display.getDefault().asyncExec(new Runnable() {

                                    @Override
                                    public void run() {
                                        listCreatedFiles.add(authFilepath);
                                        listCreatedFiles.setSelection(0);
                                    }
                                });
                            }
                        } catch (Exception ex) {
                            ex.printStackTrace();
                            LOG.log(new org.eclipse.core.runtime.Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@createServicePrincipalAsync@SrvPriCreationStatusDialog", ex));
                        }
                    }
                }
            }
        }
        new ProgressMonitorDialog(this.getShell()).run(true, true, new StatusTask());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(com.microsoft.azuretools.authmanage.srvpri.step.Status) TableItem(org.eclipse.swt.widgets.TableItem) IListener(com.microsoft.azuretools.authmanage.srvpri.report.IListener) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with Status

use of com.microsoft.azuretools.authmanage.srvpri.step.Status in project azure-tools-for-java by Microsoft.

the class Program method createSp.

@SuppressWarnings("unused")
private static void createSp() {
    try {
        LogManager.getLogManager().reset();
        boolean doFirst = false;
        AdAuthManager adAuthManager = AdAuthManager.getInstance();
        if (doFirst) {
            if (adAuthManager.isSignedIn()) {
                adAuthManager.signOut();
            //AuthMethodManager.getInstance().clean(AuthMethod.AD);
            }
            adAuthManager.signIn();
        } else {
            if (!adAuthManager.isSignedIn())
                adAuthManager.signIn();
        }
        Map<String, List<String>> tsm = adAuthManager.getAccountTenantsAndSubscriptions();
        for (String tid : tsm.keySet()) {
            List<String> sids = tsm.get(tid);
            if (!sids.isEmpty()) {
                try {
                    SrvPriManager.createSp(tid, sids, "808", new IListener<Status>() {

                        @Override
                        public void listen(Status message) {
                            System.out.format(">> Status report: %s\t:\t%s\t:\t%s\n", message.getAction(), message.getResult(), message.getDetails());
                        }
                    }, null);
                } catch (Exception t1) {
                    System.out.println("CreateServicePrincipalsAction ex: " + t1.getMessage());
                    t1.printStackTrace();
                }
            }
        }
    } catch (Exception t) {
        t.printStackTrace();
    }
}
Also used : Status(com.microsoft.azuretools.authmanage.srvpri.step.Status) List(java.util.List) AdAuthManager(com.microsoft.azuretools.authmanage.AdAuthManager) IOException(java.io.IOException)

Aggregations

Status (com.microsoft.azuretools.authmanage.srvpri.step.Status)2 AdAuthManager (com.microsoft.azuretools.authmanage.AdAuthManager)1 IListener (com.microsoft.azuretools.authmanage.srvpri.report.IListener)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 List (java.util.List)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IStatus (org.eclipse.core.runtime.IStatus)1 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 TableItem (org.eclipse.swt.widgets.TableItem)1