Search in sources :

Example 71 with Nullable

use of javax.annotation.Nullable in project legacy-jclouds-examples by jclouds.

the class WindowsInstanceStarter method run.

public void run() {
    final String region = arguments.getRegion();
    // Build a template
    Template template = computeService.templateBuilder().locationId(region).imageNameMatches(arguments.getImageNamePattern()).hardwareId(arguments.getInstanceType()).build();
    logger.info("Selected AMI is: %s", template.getImage().toString());
    template.getOptions().inboundPorts(3389);
    // Create the node
    logger.info("Creating node and waiting for it to become available");
    Set<? extends NodeMetadata> nodes = null;
    try {
        nodes = computeService.createNodesInGroup("basic-ami", 1, template);
    } catch (RunNodesException e) {
        logger.error(e, "Unable to start nodes; aborting");
        return;
    }
    NodeMetadata node = Iterables.getOnlyElement(nodes);
    // Wait for the administrator password
    logger.info("Waiting for administrator password to become available");
    // This predicate will call EC2's API to get the Windows Administrator
    // password, and returns true if there is password data available.
    Predicate<String> passwordReady = new Predicate<String>() {

        @Override
        public boolean apply(@Nullable String s) {
            if (Strings.isNullOrEmpty(s))
                return false;
            PasswordData data = ec2Client.getWindowsServices().getPasswordDataInRegion(region, s);
            if (data == null)
                return false;
            return !Strings.isNullOrEmpty(data.getPasswordData());
        }
    };
    // Now wait, using RetryablePredicate
    final int maxWait = 600;
    final int period = 10;
    final TimeUnit timeUnit = TimeUnit.SECONDS;
    RetryablePredicate<String> passwordReadyRetryable = new RetryablePredicate<String>(passwordReady, maxWait, period, timeUnit);
    boolean isPasswordReady = passwordReadyRetryable.apply(node.getProviderId());
    if (!isPasswordReady) {
        logger.error("Password is not ready after %s %s - aborting and shutting down node", maxWait, timeUnit.toString());
        computeService.destroyNode(node.getId());
        return;
    }
    // Now we can get the password data, decrypt it, and get a LoginCredentials instance
    PasswordDataAndPrivateKey dataAndKey = new PasswordDataAndPrivateKey(ec2Client.getWindowsServices().getPasswordDataInRegion(region, node.getProviderId()), node.getCredentials().getPrivateKey());
    WindowsLoginCredentialsFromEncryptedData f = context.getUtils().getInjector().getInstance(WindowsLoginCredentialsFromEncryptedData.class);
    LoginCredentials credentials = f.apply(dataAndKey);
    // Send to the log the details you need to log in to the instance with RDP
    String publicIp = Iterables.getFirst(node.getPublicAddresses(), null);
    logger.info("IP address: %s", publicIp);
    logger.info("Login name: %s", credentials.getUser());
    logger.info("Password:   %s", credentials.getPassword());
    // Wait for Enter on the console
    logger.info("Hit Enter to shut down the node.");
    InputStreamReader converter = new InputStreamReader(System.in);
    BufferedReader in = new BufferedReader(converter);
    try {
        in.readLine();
    } catch (IOException e) {
        logger.error(e, "IOException while reading console input");
    }
    // Tidy up
    logger.info("Shutting down");
    computeService.destroyNode(node.getId());
}
Also used : RetryablePredicate(org.jclouds.predicates.RetryablePredicate) WindowsLoginCredentialsFromEncryptedData(org.jclouds.ec2.compute.functions.WindowsLoginCredentialsFromEncryptedData) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) Template(org.jclouds.compute.domain.Template) Predicate(com.google.common.base.Predicate) RetryablePredicate(org.jclouds.predicates.RetryablePredicate) NodeMetadata(org.jclouds.compute.domain.NodeMetadata) LoginCredentials(org.jclouds.domain.LoginCredentials) RunNodesException(org.jclouds.compute.RunNodesException) PasswordData(org.jclouds.ec2.domain.PasswordData) BufferedReader(java.io.BufferedReader) TimeUnit(java.util.concurrent.TimeUnit) PasswordDataAndPrivateKey(org.jclouds.ec2.compute.domain.PasswordDataAndPrivateKey) Nullable(javax.annotation.Nullable)

Example 72 with Nullable

use of javax.annotation.Nullable in project jsonschema2pojo by joelittlejohn.

the class IncludeJsr305AnnotationsIT method validateNullableField.

private static void validateNullableField(Field nonnullField) {
    Nonnull nonnullAnnotation = nonnullField.getAnnotation(Nonnull.class);
    Nullable nullableAnnotation = nonnullField.getAnnotation(Nullable.class);
    assertNull("Unexpected @Nonnull annotation found.", nonnullAnnotation);
    assertNotNull("Expected @Nullable annotation is missing.", nullableAnnotation);
}
Also used : Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable)

Example 73 with Nullable

use of javax.annotation.Nullable in project immutables by immutables.

the class FactoryMethodAttributesCollector method collect.

void collect() {
    ExecutableElement factoryMethodElement = (ExecutableElement) protoclass.sourceElement();
    Parameterizable element = (Parameterizable) (factoryMethodElement.getKind() == ElementKind.CONSTRUCTOR ? factoryMethodElement.getEnclosingElement() : type.element);
    for (VariableElement parameter : factoryMethodElement.getParameters()) {
        TypeMirror returnType = parameter.asType();
        ValueAttribute attribute = new ValueAttribute();
        attribute.isGenerateAbstract = true;
        attribute.reporter = reporter;
        attribute.returnType = returnType;
        attribute.element = parameter;
        String parameterName = parameter.getSimpleName().toString();
        attribute.names = styles.forAccessorWithRaw(parameterName, parameterName);
        attribute.containingType = type;
        attributes.add(attribute);
    }
    Instantiator encodingInstantiator = protoclass.encodingInstantiator();
    @Nullable InstantiationCreator instantiationCreator = encodingInstantiator.creatorFor(element);
    for (ValueAttribute attribute : attributes) {
        attribute.initAndValidate(instantiationCreator);
    }
    if (instantiationCreator != null) {
        type.additionalImports(instantiationCreator.imports);
    }
    type.attributes.addAll(attributes);
    type.throwing = extractThrowsClause(factoryMethodElement);
}
Also used : InstantiationCreator(org.immutables.value.processor.encode.Instantiator.InstantiationCreator) TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) Parameterizable(javax.lang.model.element.Parameterizable) Instantiator(org.immutables.value.processor.encode.Instantiator) VariableElement(javax.lang.model.element.VariableElement) Nullable(javax.annotation.Nullable)

Example 74 with Nullable

use of javax.annotation.Nullable in project immutables by immutables.

the class FromSupertypesModel method isEligibleFromType.

private boolean isEligibleFromType(TypeElement typeElement, ValueAttribute attr) {
    if (!typeElement.getTypeParameters().isEmpty()) {
        return false;
    }
    @Nullable ExecutableElement accessor = findMethod(typeElement, attr.names.get);
    if (accessor == null) {
        // it (null) should never happen in theory
        return false;
    }
    boolean sameReturnType = accessor.getReturnType().toString().equals(attr.returnType.toString());
    if (sameReturnType) {
        return true;
    }
    reporter.warning("Generated 'Builder.from' method will not copy from attribute '%s'" + " because it has different return type in supertype" + " (And we cannot handle generic specialization or covarian overrides yet)." + " Sometimes it is possible to avoid this by providing abstract override method in this value object", attr.name());
    return false;
}
Also used : ExecutableElement(javax.lang.model.element.ExecutableElement) Nullable(javax.annotation.Nullable)

Example 75 with Nullable

use of javax.annotation.Nullable in project immutables by immutables.

the class ImportsTypeStringResolver method getFromSourceImports.

@Nullable
private String getFromSourceImports(String resolvable, boolean notTypeArgument) {
    SourceExtraction.Imports[] importsSet = usingType == null && originType == null ? new SourceExtraction.Imports[] {} : usingType == null ? new SourceExtraction.Imports[] { originType.sourceImports() } : originType == null || usingType == originType ? new SourceExtraction.Imports[] { usingType.sourceImports() } : new SourceExtraction.Imports[] { originType.sourceImports(), usingType.sourceImports() };
    for (SourceExtraction.Imports imports : importsSet) {
        @Nullable String resolved = imports.classes.get(resolvable);
        if (resolved != null) {
            return resolved;
        }
    }
    if (extendedClasses != null)
        for (TypeElement type : extendedClasses) {
            DeclaringType top = round.declaringTypeFrom(type).associatedTopLevel();
            @Nullable String resolved = top.sourceImports().classes.get(resolvable);
            if (resolved != null) {
                return resolved;
            }
        }
    if (implementedInterfaces != null) {
        for (TypeElement type : implementedInterfaces) {
            DeclaringType top = round.declaringTypeFrom(type).associatedTopLevel();
            @Nullable String resolved = top.sourceImports().classes.get(resolvable);
            if (resolved != null) {
                return resolved;
            }
        }
    }
    // where types are present and are different
    if (notTypeArgument && originType != null) {
        if (!hasStarImports(importsSet)) {
            // Strongly assuming it comes from originating type's package
            return originType.packageOf().name() + "." + resolvable;
        }
    }
    return null;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) DeclaringType(org.immutables.value.processor.meta.Proto.DeclaringType) SourceExtraction(org.immutables.generator.SourceExtraction) Nullable(javax.annotation.Nullable) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)735 IOException (java.io.IOException)85 Test (org.junit.Test)59 Map (java.util.Map)58 Function (com.google.common.base.Function)57 List (java.util.List)55 ArrayList (java.util.ArrayList)43 File (java.io.File)42 HashMap (java.util.HashMap)37 ItemStack (net.minecraft.item.ItemStack)36 ImmutableList (com.google.common.collect.ImmutableList)32 SkyKey (com.google.devtools.build.skyframe.SkyKey)28 Nonnull (javax.annotation.Nonnull)28 ImmutableMap (com.google.common.collect.ImmutableMap)27 Predicate (com.google.common.base.Predicate)26 URL (java.net.URL)22 Label (com.google.devtools.build.lib.cmdline.Label)21 HashSet (java.util.HashSet)20 Collectors (java.util.stream.Collectors)15 TypeElement (javax.lang.model.element.TypeElement)15